How to fix Error in f(…) : Aesthetics can not vary with a ribbon

那年仲夏 提交于 2021-01-29 13:41:54

问题


I'm using ggplot2 to create a stacked area chart showing footprint (area) of a number of different research stations over time. I would like something that looks like the chart below, but with Area on the y axis and colored by the different research stations:


(source: r-graph-gallery.com)

I've tried elements of similar posts, but can't get it to work.

Trouble with ggplot in R - "Error in f(...) : Aesthetics can not vary with a ribbon"

Getting a stacked area plot in R

https://www.r-graph-gallery.com/136-stacked-area-chart/

I've provided a .csv subset of the data here.

Below is the code that I'm using.

fp <- read.csv("fp.csv")

fp$Year <- as.numeric(rep(fp$Year)) #change Year to numeric

p2 <- fp %>% 
  filter(Exist == 1) %>% # Select only existing structures
  group_by(Year, Station) %>%
  summarise(Sum_Area = sum(Area)) %>% 
  arrange(desc(Year)) %>% 
  ggplot(aes(x = Year, y = Sum_Area, fill = Sum_Area)) +
  geom_area(stat = "identity", position = "stack")
p2

I always get the error message: Error in f(...) : Aesthetics can not vary with a ribbon

来源:https://stackoverflow.com/questions/57333161/how-to-fix-error-in-f-aesthetics-can-not-vary-with-a-ribbon

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!