Note that there are some explanatory texts on larger screens.

plurals
  1. POggplot2 customized theme: axis title direction issue
    text
    copied!<p>I have problem with my customized ggplot2 theme. Within the theme I customized so that all text will have angle=0, this is a required option when describing the theme. But then by y-axis label is also directed horizontally, whereas I would like to have it at angle=90 because it doesn't fit in the plot. My code for the custom theme is:</p> <pre><code>windowsFonts(Courier=windowsFont("Courier")) my_theme&lt;-function (base_size = 12, base_family = "") { theme(text = element_text(size = base_size, family = "Courier", face = "plain", colour = "black", hjust = 0.5, vjust = 0.5, angle = 0, lineheight = 0.9), axis.text = element_text(size = rel(0.8)), axis.ticks = element_line(colour = "black"), axis.title.y = element_text(vjust=0.1,angle=90), legend.key = element_rect(colour = "grey80"), plot.title = element_text(size = rel(2), colour = "blue",face="bold"), legend.title = element_text(size = rel(1), colour = "blue"), panel.background = element_rect(fill = "white",colour = NA), panel.border = element_rect(fill = NA, colour = "grey50"), panel.grid.major = element_line(colour = "grey50", size = 0.33,linetype="dashed"), panel.grid.minor = element_blank(), strip.background = element_rect(fill = "grey80", colour = "grey50"), strip.background = element_rect(fill = "grey80", colour = "grey50")) } </code></pre> <p>Here I add axis.title.y=element_text(vjust=0.1,angle=90), but when I draw the plot is still at angle=0. Then I added it manually again:</p> <pre><code>p &lt;- ggplot(data, aes(x=variable)) p + geom_histogram()+ labs(title = "Plot title",x = "X title", y="Y title")+ my_theme()+theme(axis.title.y=element_text(angle=90)) </code></pre> <p>But still no luck. When I draw the plot without my theme everything is ok, so I guess it's the "angle" option at text=element_text(...) that fixing the angle for any text in the plot. Any options how I can make y-axis title rotate while using my theme? Any suggestions is highly appreciated :)</p> <p>UPD: example using diamonds db from ggplot2 package: Head of the dataset:</p> <pre><code> carat price color clarity 1 0.23 326 E SI2 2 0.21 326 E SI1 3 0.23 327 E VS1 4 0.29 334 I VS2 5 0.31 335 J SI2 6 0.24 336 J VVS2 7 0.24 336 I VVS1 8 0.26 337 H SI1 9 0.22 337 E VS2 10 0.23 338 H VS1 </code></pre> <p>As it seen, the plot doesn't show complete title as it cropped in the leftside</p> <pre><code>data(diamonds) p &lt;- ggplot(data=diamonds, aes(x=clarity, y=price, fill=clarity)) p+geom_bar(width=.7, stat="identity") + + guides(fill=FALSE)+my_theme()+theme( + axis.title.y=element_text(angle=90))+ + xlab("X title")+ylab("Y title")+ + ggtitle("The big title") </code></pre> <p><img src="https://i.stack.imgur.com/stmdk.png" alt="enter image description here"></p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload