Search code examples
rggplot2fonts

title font size in ggplot2 does not change


I know this is a very basic question, but I have trouble changing font size of axis labels in ggplot2. I used the code like below:

a <- ggplot(data1,  aes(x=data2, y=data3)) + 
geom_hline(yintercept=c(1, -1)) + 
labs(x = data2, y = data3) + 
theme_bw() + 
theme(axis.text=element_text(size=10))

I tried to change the axis label size but they do not change.... Does anybody have suggestion?


Solution

  • Check out here how to alter labels in ggplot: http://www.sthda.com/english/wiki/ggplot2-title-main-axis-and-legend-titles

    In the example below we use axis.title to change the size, colour and face of the text.

    library(ggplot2)
    ggplot(mtcars,  aes(x=mpg, y=disp)) +
      geom_point() + 
      theme_bw() + 
      theme(axis.title=element_text(size=10, colour = "red", face = "bold"))
    

    enter image description here