[R] ggplot: add percentage for each element in legend and remove tick mark

Kai Yang y@ngk@|9999 @end|ng |rom y@hoo@com
Thu Aug 12 17:38:42 CEST 2021


Hello List,
I use the following code to generate a donut plot.
# Compute percentages
eth$fraction = eth$individuals / sum(eth$individuals)
# Compute the cumulative percentages (top of each rectangle)
eth$ymax = cumsum(eth$fraction)
# Compute the bottom of each rectangle
eth$ymin = c(0, head(eth$ymax, n=-1))
# Make the plot using percentage
ggplot(eth, aes(ymax=ymax, ymin=ymin, xmax=4, xmin=3, fill=ethnicity)) +
  geom_rect() +
  coord_polar(theta="y")  +
  xlim(c(2, 4) 
  ) 

I want to improve the plot for two thing: 
1. the legend: I need to add percentage (eth$fraction * 100 and then add %) for each of element.
2. remove all number (tick mark ?) around the plot
Please help
Thank you,
Kai

	[[alternative HTML version deleted]]



More information about the R-help mailing list