如何更改R中的x刻度标签(移动标签和更改角度)

时间:2016-09-22 15:37:44

标签: r ggplot2 boxplot axis-labels

为了让我的图表呈现出来,我试图在x轴上移动刻度标签。我想移动标签,所以不要碰到图表和数据。我目前的图表代码如下:

 ggplot(Duffel_plotdat, aes(Afkorting, est)) + geom_point() + geom_errorbar(aes(ymin=est-se, ymax=est+se)) + labs(title="Variance loggers for each AHS") + xlab("Artificial hibernation structures") + ylab("Variance") +
scale_x_discrete(breaks=c("BL","BW","H","K","MB","MCD","WK"),
                 labels=c("Loose in brick", "In brick closed\nwith cotton wool", "Square\nceiling box", "Wall logger\ndirectly on wall", "Wall logger\non wooden cube", "Middle of\nCD-rack", "Wall plate box")) +
  theme(axis.text.x = element_text(angle=45))

给出这张图: Boxplot

我发现了关于这个主题的另一个问题(change the position (move) of tick labels when plotting with matplotlib),但由于这些数字不再可用,我无法确定这是否对我有帮助。

最后我想要改变角度,以便标签名称以另一种方式倾斜(从左上角到右下角)。我尝试使用

这样做
angle=135 

使角度变得严格,但将文本颠倒过来。

1 个答案:

答案 0 :(得分:1)

使用以下代码:

ggplot(Duffel_plotdat, aes(Afkorting, est)) + geom_point() + geom_errorbar(aes(ymin=est-se, ymax=est+se)) + labs(title="Variance loggers for each AHS") + xlab("Artificial hibernation structures") + ylab("Variance") +
scale_x_discrete(breaks=c("BL","BW","H","K","MB","MCD","WK"),
                 labels=c("Loose in brick", "In brick closed\nwith cotton wool", "Square\nceiling box", "Wall logger\ndirectly on wall", "Wall logger\non wooden cube", "Middle of\nCD-rack", "Wall plate box")) +
  theme(axis.text.x = element_text(vjust=0.6, angle=-45))

给出下图: New Boxplot