问题
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