Search code examples
rggplot2ggpubrcowplot

ggarrange not showing axis labels


I have made 4 circular boxplots with ggplot2 and they look ok individually (although ideally, I would like the x-axis names further outside of the plot).

One circular boxplot But when I use ggarrange from the ggpubr package to make a multi-panel plot my axis names are partially missing.

ggarranged circular boxplots

With the following code:

          ncol = 2, nrow = 2, font.label = list(size = 25)) 

I have also tried Gridextra and cowplot but I get the same issue.

Any help anyone can give would be highly appreciated.

Many thanks,

Annalise


Solution

  • Text labels on the x axis of polar plots can be problematic. You might want to try coord_curvedpolar from the geomtextpath package, which allows the labels to curve around the plot, helping to prevent clashes and clipping. Additionally the labels can eadily be moved radially outwards or inwards using vjust

    Obviously, I don't have your data, but here's a mock-up:

    library(ggplot2)
    
    df <- data.frame(Season = c("Winter\n2019", "Summer\n2019", "Autumn\n2019", 
                                "Winter\n2020", "Summer\n2020", "Autumn\n2020"),
                     Index = c(54.5, 55.5, 55, 56.4, 53.6, 55.5))
    
    col_list <- list(c("#d14719", "#ffd175"), 
                     c("#751975", "#ffa3d1"),
                     c("#146f6f", "#75ffff"),
                     c("#751919", "#fe1818"))
    
    p <- lapply(col_list, function(x) {
      ggplot(df, aes(factor(Season, Season), Index, fill = Index)) +
        geom_col() +
        theme_minimal(base_family = "Roboto Condensed", base_size = 12) +
        geom_vline(xintercept = 1:6, linetype = 2) +
        geom_errorbar(aes(ymin = Index - 5, ymax = Index + 5), width = 0.5) +
        geomtextpath::coord_curvedpolar() +
        scale_fill_gradient(low = x[1], high = x[2]) +
        labs(fill = "Average Total Carlson State Index") +
        guides(fill = guide_colorsteps(title.position = "top", title.hjust = 0.5)) +
        theme(legend.position = "bottom",
              legend.key.width = unit(1.5, "cm"),
              legend.key.height = unit(1.5, "mm"),
              axis.text.y = element_blank(),
              axis.title = element_blank(),
              axis.text.x = element_text(face = "bold", vjust = 0.5))
    })
    
    ggpubr::ggarrange(plotlist = p)
    

    enter image description here