我正在尝试从如here所示的moonBook包中生成类似于此图表的内容

我的数据涉及几十个组织的远程工作计划的参与度,我所有的数据都是总百分比,而不是个人回应。
因此,对于组织X,我知道:
Telework rate: 33%
No telework rate: 67%对于那些进行远程工作的人,他们的频率是:
Very infrequently: 19.8%
1-2 days/month: 4.8%
1-2 days/week: 7.9%
3-4 days/week: 0.4%
Every work day: 0.1%对于那些不远程办公的人来说,他们的理由是:
Must be physically present: 11.5%
Technical limitations: 7.1%
Not authorized: 25.5%
Choose not to: 23.9%我想让中心的饼显示给定组织的远程工作/非远程工作突破,而外部的甜甜圈显示频率/原因。但我不知道如何继续,因为我发现的几乎每一个例子都是从个人回应开始的。
发布于 2020-02-08 00:22:23
这里有一个解决方案,可能真的很接近你正在寻找的。
我使用了一些与您展示的数据类似的数据:
df<-data.frame(Org=c("Tele",rep(c("Tele","NotTele"),each=4)),
CatFreq = LETTERS[1:9],
Freq = c(19.8,4.8,7.9,0.4,0.1,11.5,7.1,25.5,22.9))代码的其余部分
library(tidyverse)
df %>%
#Calculate cumulative sums
mutate(cumsum = cumsum(Freq),
min = cumsum-Freq) %>%
#Calculate cumulative sums by Org
group_by(Org) %>%
mutate(cumsum2 = max(cumsum(Freq))) %>%
ungroup() %>%
#Get mid point to print labels for Org levels
mutate(mid = ifelse(Org == "Tele", cumsum2 / 2, min(cumsum2) + (max(cumsum2)/2) ) ) %>%
#Do the ggplot by doing two geom_rect, 1 for Org, 1 for CatFreq
ggplot()+
geom_rect(aes(xmin = 1,
xmax = 2,
ymin = min,
ymax = cumsum,
fill = Org))+
#Add labels for Org
geom_text(aes(x = 1 + ((2 - 1)/2),
y = mid,
label = paste(Org, paste0(cumsum2, "%"), sep= "\n"))) +
geom_rect(aes(xmin = 2,
xmax = 3,
ymin = min,
ymax = cumsum,
fill = CatFreq))+
#Add labels for CatFreq
geom_text(aes(x = 2 + ((3 - 2)/2),
y = min + ((cumsum - min)/2),
label = paste(CatFreq, paste0(Freq, " %"), sep= "\n"))) +
#Changing the plot to pie
coord_polar("y", start = 0) +
#Making it a doughnut
xlim(c(0,4)) +
#Set theme void
theme_void() +
#Eliminate legend
theme(legend.position = "none")

https://stackoverflow.com/questions/60115324
复制相似问题