Search code examples
rggplot2graphsize

How to change legend size but not titles with ggplot in r?


I need some help changing the size of the titles but not the legends(y axis). I can not change them separately.

Also I need to change the graph size, more taller.

Thanks

grafico <- ggplot(meanIMcomunas, aes(x= IM, y= Comuna)) 
          + geom_point(aes(color = IM),size =2) 
          + labs(title = "Promedio de IM por comuna")
          + theme(text =element_text(size = 2))+scale_color_viridis(option = "D") 

enter image description here


Solution

  • The theme ggplot function has a lot of different pointers to different features of your plot you want to change. Adapting the code you provided plot.title will ONLY increase the font size of your plots title. There are other specifications for axis titles and legend titles that will only change those fonts as well (see axis.text and legend.text as well as there variations).

    grafico <- ggplot(meanIMcomunas, aes(x= IM, y= Comuna)) 
              + geom_point(aes(color = IM),size =2) 
              + labs(title = "Promedio de IM por comuna")
              + theme(plot.title = element_text(size = 20))+ 
    scale_color_viridis(option = "D") 
    

    You can change the size of the plot when you save it by specifying the width and height and changing the units:

    ggsave(grafico, file = "my_file.png", width = 10, height = 10, units = "in")