I am using the code given in this answer to generate this plot
library(rvest)
cachedir <- "cache"
if (!dir.exists(cachedir)) dir.create(cachedir)
URL <- "https://github.com/CSSEGISandData/COVID-19/tree/master/csse_covid_19_data/csse_covid_19_daily_reports"
html <- read_html(URL)
csvlinks <- html_nodes(html, "td span") %>%
html_nodes("a") %>%
html_attr("href") %>%
grep("csv$", ., value = TRUE) %>%
paste0("https://raw.githubusercontent.com", .) %>%
gsub("/blob", "", .)
csvfiles <- file.path(cachedir, basename(csvlinks))
donothave <- !file.exists(csvfiles)
csvlinks <- csvlinks[donothave]
csvfiles <- csvfiles[donothave]
ign <- Map(function(l,f) download.file(l, f, quiet=TRUE), csvlinks, csvfiles)
csvfiles2 <- list.files(path = cachedir, pattern = "csv$", full.names = TRUE)
list_of_frames <- lapply(csvfiles2, read.csv, stringsAsFactors = FALSE)
list_of_frames2 <- lapply(list_of_frames, function(x) {
colnames(x) <- gsub(".*\\.", "", colnames(x))
x
})
renamer <- c(
State = "Province_State",
Region = "Country_Region",
Update = "Last_Update",
Latitude = "Lat",
Longitude = "Long_"
)
list_of_frames3 <- lapply(list_of_frames2, function(x) {
nms <- colnames(x)
colnames(x) <- ifelse(nms %in% names(renamer), renamer[ nms ], nms)
x
})
alldata <- data.table::rbindlist(list_of_frames3, fill = TRUE)
fmts <- c("%m/%d/%y %H:%M", "%m/%d/%Y %H:%M", "%Y-%m-%d %H:%M:%S", "%Y-%m-%dT%H:%M:%S")
timestamp <- rep(Sys.time()[NA], nrow(alldata))
for (fmt in fmts) {
if (!any(isna <- is.na(timestamp))) next
timestamp[isna] <- as.POSIXct(alldata$Last_Update[isna], format = fmt)
}
alldata$Last_Update <- timestamp
Atlantic <- alldata[alldata$Admin2=="Atlantic",]
Atlantic[,Atlantic$Confirmed]
#[1] 5 6 6 12 10 14 17 24 29
Atlantic[,Atlantic$Last_Update]
#[1] "2020-03-22 23:45:00 EDT" "2020-03-23 23:19:34 EDT"
#[3] "2020-03-24 23:37:31 EDT" "2020-03-25 23:33:19 EDT"
#[5] "2020-03-26 23:48:35 EDT" "2020-03-27 22:14:55 EDT"
#[7] "2020-03-28 23:05:37 EDT" "2020-03-29 23:08:25 EDT"
#[9] "2020-03-30 22:52:45 EDT"
plot("Confirmed", "Last_update", Atlantic, xaxt='n')
#Error in plot.window(...) : need finite 'xlim' values
#In addition: Warning messages:
#1: In xy.coords(x, y, xlabel, ylabel, log) : NAs introduced by coercion
#2: In xy.coords(x, y, xlabel, ylabel, log) : NAs introduced by coercion
#3: In min(x) : no non-missing arguments to min; returning Inf
#4: In max(x) : no non-missing arguments to max; returning -Inf
#5: In min(x) : no non-missing arguments to min; returning Inf
#6: In max(x) : no non-missing arguments to max; returning -Inf
axis.Date(1,at=alldata$Last_Update,labels=format(alldata$Last_Update,"%y-m-%d"),las=2)
I tried modifying the structure of the time format to no avail.
With this line, you are calling the base R plot
And plot a character versus another character, which is not going to work. So most likely you need something like this: