I'm trying to create a stacked area graph with R using the package ggplot2 with the below data:
> dput(ec.admin1.ma.tall[1:20,])
structure(list(date = structure(c(18346, 18347, 18348, 18349,
18350, 18351, 18352, 18353, 18362, 18363, 18364, 18365, 18366,
18367, 18354, 18374, 18375, 18376, 18379, 18380), class = "Date"),
locations = structure(c(1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L,
1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L), .Label = c("azuay_newcase_avg",
"bolivar_newcase_avg", "canar_newcase_avg", "carchi_newcase_avg",
"chimborazo_newcase_avg", "cotopaxi_newcase_avg", "eloro_newcase_avg",
"esmeraldas_newcase_avg", "galapagos_newcase_avg", "guayas_newcase_avg",
"imbabura_newcase_avg", "loja_newcase_avg", "losrios_newcase_avg",
"manabi_newcase_avg", "moronasant_newcase_avg", "napo_newcase_avg",
"orellana_newcase_avg", "pastaza_newcase_avg", "pichincha_newcase_avg",
"santaelena_newcase_avg", "stodom_newcase_avg", "sucumbios_newcase_avg",
"tungurahua_newcase_avg", "zamchin_newcase_avg"), class = "factor"),
newcases_ma = c(NA, NA, NA, 5.85714285714286, 8.14285714285714,
13.1428571428571, 12.8571428571429, 16.2857142857143, 15.2857142857143,
16.1428571428571, 14.2857142857143, 12.5714285714286, 18,
19.2857142857143, 39.2857142857143, 38.7142857142857, 53.2857142857143,
53, 52.4285714285714, 46)), row.names = c(NA, 20L), class = "data.frame")
> ec.admin1.ma.tall$locations <- factor(ec.admin1.ma.tall$locations)
> ec.admin1.ma.tall$date <- as.Date(ec.admin1.ma.tall$date, "%m/%d/%Y")
> ggplot(ec.admin1.ma.tall, aes(x = date, y = newcases_ma, fill = locations, group =
locations)) + geom_area()
The image I get from this code is: Stacked Area Graph plotting number of new cases by region
However, from plotting the individual regions, I don't believe my plot is accurate. The code for this plot is below:
ggplot(ec.admin1.ma.tall, aes(x = date, y = newcases_ma, fill = locations)) +
geom_col() +
labs(title = "Moving 7-Day Average for New Cases in Admin 1 Regions - Ecuador",
x = "Date", y = "7-Day Moving Average, New Cases") +
theme(axis.text.x = element_text(angle = 90, size = rel(0.5), vjust = 0.5, hjust=1)) +
facet_wrap(~locations, nrow = 6, scales = "free")
Bar graph of new cases over time, split by individual regions
As you can see from the y-axis of these individual regions, none of the values go above 2000 and not many go even above 1000 cases. Would anyone know why there is this discrepancy between the individual region's data and the stacked area graph?