我想使用 ggplot2 添加阴影区域,连接每个条形的类别,如图所示

数据
library(ggplot2)
specie <- c(rep("sorgho" , 3) , rep("poacee" , 3) , rep("banana" , 3) , rep("triticum" , 3) )
condition <- rep(c("normal" , "stress" , "Nitrogen") , 4)
value <- abs(rnorm(12 , 0 , 15))
data <- data.frame(specie,condition,value)
ggplot(data, aes(fill=condition, y=value, x=specie)) +
geom_bar(position="fill", stat="identity", width = .5)
Run Code Online (Sandbox Code Playgroud)
我想创建一个如下图所示的图表。它是一种使用 geom_area 和 geom_point 的组合。
\n\n假设我的数据如下所示:
\nlibrary(gcookbook, janitor)\n\nggplot(uspopage, aes(x = Year, y = Thousands, fill = AgeGroup)) +\n geom_area()\nRun Code Online (Sandbox Code Playgroud)\n\n然后,我想添加确切的点数作为每个类别的总数,即:
\nlibrary(dplyr)\nuspopage |> \n group_by(AgeGroup) |> \n summarize(total = sum(Thousands))\n\n# A tibble: 8 \xc3\x97 2\n AgeGroup total\n <fct> <int>\n1 <5 1534529\n2 5-14 2993842\n3 15-24 2836739\n4 25-34 2635986\n5 35-44 2331680\n6 45-54 1883088\n7 55-64 1417496\n8 >64 1588163\nRun Code Online (Sandbox Code Playgroud)\n