【发布时间】:2022-01-21 06:17:51
【问题描述】:
我已经创建了一个融合数据框,其中包含几年的能源百分比(因子变量)作为附加因子或日期:
我怎样才能用ggplot(或plotrix)为不同年份制作漂亮的多面饼图?
到目前为止,我已经达到了:
ggplot(melted_df, aes(x=Year, y=Share, fill=Source)) +
geom_bar(stat="identity", width=1)+
coord_polar("y", start=0) +
geom_text(aes(label = paste0(round(Share*100), "%")), position = position_stack(vjust = 0.5),size=3)+
labs(x = NULL, y = NULL, fill = NULL, title = "Energy Mix")+
theme_classic() + theme(axis.line = element_blank(),
axis.text = element_blank(),
axis.ticks = element_blank(),
plot.title = element_text(hjust = 0.5, color = "#666666"))
【问题讨论】:
-
很难演示没有样本数据的解决方案供我们使用。我会尝试
aes(x=1...而不是x=Year或facet_wrap(~Year, scales = free_x) -
使用
dput(...)获取数据的可粘贴版本。您的数据图像不是很有帮助。此外,饼图很难阅读,使用条形图几乎总是更好。 -
非常感谢乔恩·斯普林。有效。现在,我只是想知道如何将饼图标签放在切片之外。再次感谢!
标签: r ggplot2 pie-chart melt facet-wrap