Search code examples
rgraphaxis-labelsfrequency-analysis

break axis labels in R (Using sjp.frq function)


I'm making some frequency graphs using the sjp.frq function, but the axis labels are to big and I would like to break those in two lines. The graph shows that the axis labels are one on the top of the other. How do I change this?

Thanks for the help!

library(sjPlot)
library(sjmisc)

set_theme(base = theme_classic(),  axis.title.size = 0,  geom.label.size = 4.5, 
                  axis.textsize.x = 1.1, axis.textsize.y = 1.1 )

sjp.frq(base$x, type = c("bar"), sort.frq = c("desc"), geom.colors = "grey")

Solution

  • Although no sample data is given, here's are two fixes that may work

    library(sjPlot)
    library(sjmisc)
    
    set_theme(base = theme_classic(),  axis.title.size = 0,  geom.label.size = 4.5, 
                      axis.textsize.x = 1.1, axis.textsize.y = 1.1 )
    
    sjp.frq(base$x, type = c("bar"), sort.frq = c("desc"), geom.colors = "grey",coord.flip =TRUE) #Flip the corrdinate and check if that avoids the overlap.
    

    If the above does't work, try setting the axis.angle.x argument as follows

    library(sjPlot)
    library(sjmisc)
    
    set_theme(base = theme_classic(),  axis.title.size = 0,  geom.label.size = 4.5, 
                      axis.textsize.x = 1.1, axis.textsize.y = 1.1,axis.angle.x = 45 )#this should slant the text to avoid the overlap
    
    sjp.frq(base$x, type = c("bar"), sort.frq = c("desc"), geom.colors = "grey")