我试图让geom_area生成一个堆叠面积图,但它生成了一个入口图。下面是一个例子
library(dplyr)
library(ggplot2)
x = expand.grid(name = c("D01", "D02", "D03", "D04"), component = c("F", "W", "M", "V"))
value = runif( min = 20, max = 150, nrow(x))
data2 = cbind(x, value) %>%
dplyr::arrange(name)
ggplot2::ggplot(data = data2, aes(x = name, fill = factor(component))) +
ggplot2::geom_area(aes(y = value), position = 'stack') 我阅读了问题Why is my stacked area graph in ggplot2 empty和Why is my stacked area graph in ggplot2 empty,但那里发布的解决方案并没有解决我的问题。谢谢你的建议。
发布于 2020-05-18 10:25:06
如果我们将'x‘factor转换为integer,它应该可以工作
library(ggplot2)
library(dplyr)
data2 %>%
mutate(name = as.integer(name)) %>%
ggplot(aes(x = name, fill = component)) +
geom_area(aes(y = value), position = 'stack')+
scale_x_continuous(labels = levels(data2$name))

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