【发布时间】:2019-09-15 08:30:25
【问题描述】:
我有一个条形图,我还想在其中包含一些显示它们之间百分比差异的线条,如下图所示:
图中的线条只是为了说明我的理想状态。
有人可以帮我解决这个问题吗?
这里是复制图的数据框:
structure(list(shares = c(0.39, 3.04, 9.32, 22.29, 64.97, 0.01,
0.11, 5.83, 21.4, 72.64), quantile = structure(c(4L, 1L, 2L,
3L, 5L, 4L, 1L, 2L, 3L, 5L), .Label = c("2nd Quantile", "3rd Quantile",
"4nd Quantile", "Poorest 20%", "Richest 20%"), class = "factor"),
case = structure(c(1L, 1L, 1L, 1L, 1L, 2L, 2L, 2L, 2L, 2L
), .Label = c("No Debt", "With Debt"), class = "factor")), row.names = c(NA,
-10L), class = "data.frame")
这是我用来制作条形图的代码:
ggplot(df_cum, aes(fill = case , quantile, shares)) + geom_bar(position =
"dodge", stat = "identity") +
scale_x_discrete(limits = c(
"Poorest 20%",
"2nd Quantile",
"3rd Quantile",
"4nd Quantile",
"Richest 20%"
)) +
theme_minimal()
【问题讨论】: