Sorry in advance if I'm not very clear in the explanation of my problem (I'm very new to R) but I am trying to graph 2 variables (Average cereal yield, Average land area change) into the same area chart to show the difference between cereal yield growth and land area change between a date range but I can't figure out how to get it to work the way I want it to. Here's a picture of my initial dataset with respective variables:
year meancereal meanland
<chr> <dbl> <dbl>
1961 100.0000 100.0000
1962 107.6528 100.9864
1963 108.3420 101.4125
1964 109.5492 104.1026
1965 111.8808 105.2984
1966 110.3679 106.5562
1967 117.0725 109.7375
1968 117.5337 112.8811
1969 120.2902 114.9961
1970 120.5337 114.4149
I've tried converting to a longer dataset so that instead of having 2 separate columns I just have one for Averages and one for Values:
year Avg value
<chr> <chr> <dbl>
1961 meancereal 100.0000
1961 meanland 100.0000
1962 meancereal 107.6528
1962 meanland 100.9864
1963 meancereal 108.3420
1963 meanland 101.4125
1964 meancereal 109.5492
1964 meanland 104.1026
1965 meancereal 111.8808
1965 meanland 105.2984
This is the code I've written so far:
landchangeC<-land_use %>%
filter(year>1960,year<2015)%>%
group_by(year) %>%
summarise( meancereal= mean(cereal_yield_index, na.rm=TRUE),
meanland=mean(land_area_change, na.rm=TRUE))
landchangeC<-landchangeC%>%
pivot_longer(meancereal:meanland, names_to="Avg", values_to="value")
landchangeC%>%
ggplot(aes(year, value, color=Avg))+
geom_line()+
geom_area()
After I run the code It just shows a blank graph:
Any help is much appreciated!