My code
For a university course i have to plot the inferred excess mortality up until 2019 and as of 2020. However, when running my code it keeps saying i have an aes error: Error in geom_line()
:
! Problem while computing aesthetics.
ℹ Error occurred in the 1st layer.
Caused by error in check_aesthetics()
:
! Aesthetics must be either length 1 or the same as the data (2296)
✖ Fix the following mappings: y
How could i solve this issue, i have tried the solutions shown on https://www.statology.org/aesthetics-must-be-either-length-1-or-same-as-data/ without any luck
Any help is appreciated! my code:
ggplot(data=preds[preds$YEAR<=2019,], aes(x=as.numeric(as.character(WEEK)), y=1E7*preds$excess_deaths/POPULATION), colour = factor(YEAR)) +
geom_line(aes(y=1E7*preds$excess_deaths/POPULATION, colour = NA)) +
geom_ribbon(data=preds[preds$YEAR<=2019,], aes(ymin=1E7*preds$lower.CI/POPULATION, ymax=1E7*preds$upper.CI/POPULATION), colour=NA, alpha=I(0.4)) +
geom_ribbon(aes(ymin=1E7*preds$excess_deaths.lower.PI/POPULATION, ymax=1E7*preds$excess_deaths.upper.PI/POPULATION), colour=NA, alpha=I(0.2)) +
geom_line(data=preds[preds$YEAR>=2020,], aes(y=1E7*preds$excess_deaths/POPULATION, colour = NA)) +
geom_ribbon(data=preds[preds$YEAR>=2020,],
aes(ymin=1E7*preds$excess_deaths.lower.CI/POPULATION, ymax=1E7*preds$excess_deaths.upper.CI/POPULATION), colour=NA, alpha=I(0.4)) +
geom_ribbon(data=preds[preds$YEAR>=2020,],
aes(ymin=1E7*preds$excess_deaths.lower.PI/POPULATION, ymax=1E7*preds$excess_deaths.upper.PI/POPULATION), colour=NA, alpha=I(0.2)) +
facet_wrap(~ model, ncol = 1) +
xlab("Date") +
ylab("Excess mortality (Per 10M inhabitants") +
ggtitle(label = 'EXCESS MORTALITY IN BELGIUM PER WEEK (PER 10M INHABITANTS)', subtitle = 'Data Statbel 2009-2022') +
theme_economist_white()
Trying to change the color and fill functions of aes according to multiple sites without any luck. Expecting the color to resemble each year. when running i received this error: Error in geom_line()
:
! Problem while computing aesthetics.
ℹ Error occurred in the 1st layer.
Caused by error in check_aesthetics()
:
! Aesthetics must be either length 1 or the same as the data (2296)
✖ Fix the following mappings: y