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

基本上在主题行中说的是什么.以下代码生成带有水平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))

但当我将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))

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

最佳答案 只需将.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)

点赞