I am working on a project with Covid data, and I wish to plot (and later compare) covid data from three countries: Netherlands, Germany, France all on the same plot.
I wish to name the x-axis "Date", the y-axis "Number of confirmed cases" and the title of the legend "COVID Cases in Countries".
So far, I have created a final data frame with the data from all three counties called "dfFinal". The ggplot I included does not work (because I dont know how to code it). I am just having trouble plotting the information. Could someone help? The data has been gathered an read using Jsonlite, and is easily re-created without needing a data-set.
structure(list(Country = c("Netherlands", "Netherlands", "Netherlands", "Netherlands", "Netherlands", "Netherlands", "Netherlands", "Netherlands", "Netherlands", "Netherlands", "Netherlands", "Netherlands", "Netherlands", "Netherlands", "Netherlands"), Date = structure(c(18317, 18318, 18319, 18320, 18321, 18322, 18323, 18324, 18325, 18326, 18327, 18328, 18329, 18330, 18331), class = "Date"), Cases = c(0L, 1L, 6L, 10L, 18L, 24L, 38L, 82L, 128L, 188L, 265L, 321L, 382L, 503L, 603L)), row.names = 36:50, class = "data.frame")
install.packages("jsonlite", dependencies = TRUE)
library("jsonlite")
tmp <- readLines("https://pomber.github.io/covid19/timeseries.json")
jsonLot <- fromJSON(tmp)
myjsonLot <- toJSON(jsonLot, pretty=TRUE)
fileConn <- file(paste0("Covid19_timeseries.json"))
writeLines(myjsonLot, fileConn)
dfN <- data.frame(Country = c("Netherlands"), Date = c(jsonLot$Netherlands$date), Cases =
c(jsonLot$Netherlands$confirmed))
dfN[,]
dfG <- data.frame(Country = c("Germany"), Date = c(jsonLot$Germany$date), Cases =
c(jsonLot$Germany$confirmed))
dfG[,]
dfF <- data.frame(Country = c("France"), Date = c(jsonLot$France$date), Cases =
c(jsonLot$France$confirmed))
dfF[,]
dfFinal <- rbind.fill(dfN, dfG, dfF)
View(dfFinal)
ggplot(dfFinal, aes(x=Date, y=Cases) + geom_line(size=1) +
xlab("Date") + ylab("Number of confirmed cases") + scale_x_datetime(breaks = "1 day") +
geom_line(aes(y=dfN$Cases), colour ="red") +
geom_line(aes(y=dfG$Cases), colour ="red") +
geom_line(aes(y=dfF$Cases), colour ="red"))
dput(df)?