When I change the axis position, ggplot stops the axis label rotation

Basically what the topic line says. The following code creates a graph with a horizontal y mark:

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

But when I move the y axis to the left, the labels become vertical!

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 :(

This seems like such a silly problem, and I'm sure I just miss something obvious. Plz help me.

+4
source share
1 answer

Just add .rightto 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 )

+2
source

Source: https://habr.com/ru/post/1671452/


All Articles