rggplot2statisticsggpairs

ggpairs change axis label font size


I have a dataset with relatively large column names. When displaying the ggpairs, they fall outside of the limit, and one cannot read the each plot labels. I have tried theme(axis.text = element_text(size=8)) inside the ggpairs() command, but it doesn't work. Can you please help me with that?


Solution

  • You should add the theme and check if you size is high enough like this:

    library(GGally)
    data(diamonds, package="ggplot2")
    diamonds.samp <- diamonds[sample(1:dim(diamonds)[1], 1000), ]
    
    pm <- ggpairs(
      diamonds.samp[, 1:5],
      mapping = ggplot2::aes(color = cut),
      upper = list(continuous = wrap("density", alpha = 0.5), combo = "box_no_facet"),
      lower = list(continuous = wrap("points", alpha = 0.3), combo = wrap("dot_no_facet", alpha = 0.4)),
      title = "Diamonds"
    )
    pm
    

    
    pm + theme(axis.text = element_text(size = 20))
    

    Created on 2022-08-10 by the reprex package (v2.0.1)