How do I to fix aspect ratio and apply coord_flip

2019-07-24 15:58发布

This question already has an answer here:

Im trying to produce the following chart in ggplot2 but I require it to be a horizontal plot rather than vertical. I also require the plot to be thin.

ggplot(Compositiondata, aes(x=1, y=`Composition`, fill=`Elements`),labels = FALSE) 
+ geom_bar(stat="identity",aes(col.axis = "white",labels=FALSE)) 
+ ggtitle("Title") 
+ theme(axis.line=element_blank(), axis.text.x=element_blank(), 
        axis.ticks.x=element_blank(), axis.title.x=element_blank(), 
        panel.background=element_blank(), panel.border=element_blank(),  
        panel.grid.major=element_blank(), panel.grid.minor=element_blank(),                                                            
        plot.background=element_blank()) 
 + coord_fixed(ratio = 0.05) +coord_flip()

When I apply coord_flip() the plot returns to its original width. How can I flip the plot and retain a small width?

标签: r ggplot2
1条回答
霸刀☆藐视天下
2楼-- · 2019-07-24 16:42

Without reproducible data, my best guess would be to pass aspect.ratio through the theme not in coord_fixed(ratio=0.05)

查看更多
登录 后发表回答