Reputation: 1
I have the following data frame.
inward_2022_region_income <- data.frame(
Region = c("South Asia", "Europe & Central Asia", "Latin America & Caribbean", "East Asia & Pacific", "Middle East & North Africa", "East Asia & Pacific", "Europe & Central Asia", "Sub-Saharan Africa", "Europe & Central Asia", "Latin America & Caribbean"),
Income_Group = c("Lower middle income", "High income", "Upper middle income", "Upper middle income", "Lower middle income", "Lower middle income", "Lower middle income", "Lower middle income", "Upper middle income", "Lower middle income"),
remittance_received = c(164363767273, 136183611220, 117465697000, 62839165858, 58043307652, 42473756742, 38171200000, 37431728299, 33900928280, 24964975447)
)
I've created a piedonut chart with the following codes.
PieDonut(inward_2022_region_income,
aes(pies = Country_Income,
donuts = Region,
count = remittance_received),
explode = 1,
explodeDonut = TRUE,
ratioByGroup = FALSE,
addDonutLabel = FALSE,
labelposition = 0.5,
donutLabelSize = 2,
pieLabelSize = 2,
titlesize = 4,
use.labels = FALSE,
title = "Inward Remittances by Income Group and Region",
maxx = 1.9,
r0 = 0,
r1 = 0.8,
r2 = 1.2,
start = pi/1,
showPieName = FALSE,
showRatioThreshold = FALSE)
The piedonut chart has been plotted as follows.
enter image description here enter image description here
The following 3 items are what I am struggling with.
[Problem 1] I would like to make the donut parts of 'High income' Pie unoverlapped and seen properly.
[Problem 2] I would like to the percentage values shown in labels as rounded numbers.
[Problem 3] I would like to change the colors of pie and donuts by using the following color codes. Colors: c("#0197FF", "#5938E4", "#22B2A4", "#15A800", "#B0DB02", "#E8B321", "#DB5614", "#F66DBD")
Upvotes: 0
Views: 793
Reputation: 1
Same problem here. I could manage to modify parts of the original PieDonut function for all the problems:
For Problem 1: What kind of worked for me was to replace the geom_text() with ggrepel::geom_text_repel
For Problem 2: I modified the section of the original function where labels were created, like this:
replaced this section:
paste0(df$label,
"\n(", scales::percent(df$ratio), ")"),
as.character(df$label)
with:
paste0(df$label,
"\n(", scales::label_percent(accuracy = 1)(df$ratio), ")"),
as.character(df$label)
For Problem 3: please refer here.
I hope this helps.
Upvotes: 0
Reputation: 29
I have a same Problem 2 with you. Yesterday, I tried this way and it fixed. I created another column which calculate % contribution, for example remittance_received in your case using mutate(remittance_received1=remittance_received/sum(remittance_received)*100) dat$remittance_received <- round(dat$remittance_received,0)
.
In the count()
function within aes(), then using count=remittance_received1
.
Hope this works for you.
Upvotes: 0