当我改变轴位置ggplot停止轴标签旋转

时间:2017-03-04 15:44:06

标签: r plot ggplot2

基本上在主题行中说了什么。以下代码生成带有水平y标签的图:

require(ggplot2)
silly.plott <- data.frame(silly = c(1,2,3,4,5), plott = c(1,2,3,4,5))
ggplot(silly.plott, aes(x = silly, y = plott))+
    geom_point()+
    theme(axis.title.y = element_text(angle = 0, vjust = 0.5))

horizontal axis lable

但是当我将y轴移动到左侧时,标签会垂直转动!

ggplot(silly.plott, aes(x = silly, y = plott))+
    geom_point()+
    scale_y_continuous(position = "right")+
    theme(axis.title.y = element_text(angle = 0, vjust = 0.5))

axis on right, vertical label :(

这感觉就像这样一个愚蠢的问题而且我很积极,我只是错过了一些明显的东西。 Plz帮助我。

1 个答案:

答案 0 :(得分:2)

只需将.right添加到axis.title.y

即可
ggplot(silly.plott, aes(x = silly, y = plott))+
geom_point()+
scale_y_continuous(position = "right")+
theme(axis.title.y.right = element_text(angle = 0, vjust = 0.5))

https://github.com/tidyverse/ggplot2/blob/master/NEWS.md

相关问题