Search code examples
rggplot2pie-chartggpubr

How can I increase canvas size or plot area so that it does not crop labels in ggpubr::ggpie?


I have the same problem as raised in ggpubr #429: ggpie cuts off long names.

It seems the canvas (?plot area - really not sure about vernacular) is too small

How could I fix it so that long names are not cropped?

Example from GH:


df <- data.frame(
  group = c("Male", "Female", "Children but not teenager"),
  value = c(25, 25, 50))

ggpie(df, "value", label = "group")

image

Appreciate your help!


Solution

  • You can edit the source code of ggpie directly using trace(ggpie, edit = TRUE) and correcting their call to coord_polar() on line 26 by adding clip = "off". This won't crop out text outside of the coordinate area. Alternatively just copy the full source code, make this edit, and save to your own custom function to get this use across sessions.

    ...) + coord_polar(theta = "y", start = 0, clip = "off") + .remove_axis()
    

    Then we get:

    ggpie(df, "value", label = "group")
    

    enter image description here

    Alternatively, as @rawr mentions below, you can replicate the coord_polar() call to get the same results, just make sure you specify theta = "y".

    ggpie(df, "value", label = "group") +
      coord_polar(theta = "y", clip = "off")