ggplot2中的交错轴标签 [英] Staggered axis labels in ggplot2
问题描述
我想将我的x轴标签错开在 ggplot2
中。令人惊讶的是,我尝试的工作(感谢@哈德利和一致的语法!)。
$ b $ pre code> c < - ggplot(mtcars,aes(factor(cyl)))
c < - c + geom_bar ()
c + theme(axis.text.x = element_text(vjust = c(0,0.1,0.2)))
但是,看起来结果是,专用于边缘的垂直空间的数量变得不必要的大。任何提示,让它回到规模?
不完全确定发生了什么,但这是一个潜在的解决方法:
c + theme(axis.text.x = element_text(vjust = grid :: unit(c(-2,0 ,2),points)))
由于某些原因,默认单位 npc
当您使用大于一个长度 vjust
向量时,包含元素大小的小数部分不起作用。我还怀疑 vjust
并不完全适用于超过一个载体的工作(不确定)。
I wanted to stagger my x-axis labels in ggplot2
. Amazingly, the thing I tried worked (thanks to @Hadley and the consistent grammar!).
c <- ggplot(mtcars, aes(factor(cyl)))
c <- c + geom_bar()
c + theme(axis.text.x = element_text(vjust = c(0, 0.1, 0.2)))
But it seems that as a consequence, the amount of vertical space dedicated to the margin became unnecessarily large. Any tips on getting this back down to size?
Not entirely sure what's going on, but here is a potential work-around:
c + theme(axis.text.x = element_text(vjust = grid::unit(c(-2, 0, 2), "points")))
For some reason the default units of npc
which are fractions of the containing element size are not working right when you use a greater than one length vjust
vector. I also suspect vjust
was not fully intended to work with longer than one vectors (not sure).
这篇关于ggplot2中的交错轴标签的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!