我的数据是
> dput(df2_m)
structure(list(FY = c("2018-19", "2019-20", "2018-19", "2019-20",
"2018-19", "2019-20", "2018-19", "2019-20"), Finance_Type = structure(c(1L,
1L, 2L, 2L, 3L, 3L, 4L, 4L), .Label = c("DF_Bank", "DF_O", "DE_SC",
"DF_E"), class = "factor"), value = c(42029, 47363, 3000, 3000,
26197, 27000, 50016, 63848)), row.names = c(NA, -8L), class = "data.frame")
我用ggplot通过以下命令创建两个饼图:
# Create a basic bar first
library(ggplot2)
pie = ggplot(df2_m, aes(x="", y=value, fill = Finance_Type)) + geom_bar(stat = "identity", width=1)
pie <- pie + facet_grid(facets =. ~ FY) # Side by side bar chart
pie <- pie + coord_polar(theta = "y", start = 0) # side by side pie chart
pie <- pie + geom_text(aes(label = paste0(round(value/(sum(value))*100), "%")), position = position_stack(vjust = 0.5))
# Add color scale (hex colors)
# pie = pie + scale_fill_manual(values=c("#55DDE0", "#33658A", "#2F4858", "#F6AE2D", "#F26419", "#999999"))
# Remove labels and add title
pie = pie + labs(x = NULL, y = NULL, fill = NULL, title = "Deficit Finance - Source")
# Tidy up the theme
pie = pie + theme_classic() + theme(axis.line = element_blank(),
axis.text = element_blank(),
axis.ticks = element_blank(),
plot.title = element_text(hjust = 0.5, color = "#666666"))
pie
问题是我的第一个饼图的一部分丢失了。如何获得两个完整的饼图?