PHPFixing
  • Privacy Policy
  • TOS
  • Ask Question
  • Contact Us
  • Home
  • PHP
  • Programming
  • SQL Injection
  • Web3.0

Friday, April 22, 2022

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

 April 22, 2022     ggplot2, ggpubr, pie-chart, r     No comments   

Issue

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")


Answered By - caldwellst
Answer Checked By - Robin (PHPFixing Admin)
  • Share This:  
  •  Facebook
  •  Twitter
  •  Stumble
  •  Digg
Newer Post Older Post Home

0 Comments:

Post a Comment

Note: Only a member of this blog may post a comment.

Total Pageviews

Featured Post

Why Learn PHP Programming

Why Learn PHP Programming A widely-used open source scripting language PHP is one of the most popular programming languages in the world. It...

Subscribe To

Posts
Atom
Posts
Comments
Atom
Comments

Copyright © PHPFixing