简体   繁体   English

如何在R中的ggplot2中的barplot中添加空间,以便可以读取标签?

[英]How can I add space in barplot from ggplot2 in R so that I can read the labels?

I am using this code: 我正在使用此代码:

ggplot2::ggplot(gtfDf, ggplot2::aes(x = type)) + 
  ggplot2::geom_bar(position = ggplot2::position_dodge(width = 2)) +
  ggplot2::xlab('Type of feature') + 
  ggplot2::ylab('Number of features') + 
  ggplot2::ggtitle('Number of features of each type in the GTF file')

to generate a plot in R. However, the labels overlap each other a bit. 以在R中生成图。但是,标签彼此重叠一点。 Does anybody know how I can space the columns more? 有人知道我如何可以更多地隔开列吗?

Did you try simply make the graph bigger? 您是否尝试过只是简单地放大图表? You can use ggsave("filename.extension", width=x, height=y) to print the last active plot object (or specify it with the argument plot=plot_name ), then simply play around with the size of your output until you're happy with it. 您可以使用ggsave("filename.extension", width=x, height=y)打印最后一个活动图对象(或使用plot=plot_name参数指定它),然后简单地plot=plot_name输出的大小,直到找到很高兴。
Not the smartest way, but since you probably want to play with the size for rendering in the end anyway... 这不是最聪明的方法,但是由于您可能还是想玩最终渲染的大小...

The items on the x-axis have x values of 1, 2, 3, and so on, though you typically don't refer to them by these numerical values. x轴上的项目的x值为1、2、3,依此类推,尽管您通常不使用这些数值来引用它们。 When you use geom_bar(width=0.9), it makes each group take up a total width of 0.9 on the x-axis so if you reduce this bar width you can space the columns more, try something like this: 当您使用geom_bar(width = 0.9)时,它会使每个组在x轴上的总宽度为0.9,因此,如果减小此bar的宽度,则可以使列间距更大,请尝试以下操作:

library(ggplot2)
ggplot(gtfDf, aes(x = type)) +
geom_bar(width=0.5, position =position_dodge(0.5))

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM