Kyoto (京都), Japan, vs. Montréal, Canada, a first comparison
Want to share your content on R-bloggers? click here if you have a blog, or here if you don't.
We just arrived in Kyoto (京都), Japan, from Montréal, Canada. Everything seems very different. I still have in mind the time I spent in Hong Kong (more than a year), but that was 25 years ago… Just to compare, I used wikipedia’s page of Kyoto vs. Montréal. Quite naturaly, I used the pages in French, but that was not stupid because the pages in English are more compex to read (with temperatures in °C and °F, humidity in mm and inches, etc).
urlM="https://fr.wikipedia.org/wiki/Montr%C3%A9al"
urlK="https://fr.wikipedia.org/wiki/Kyoto"
download.file(urlM,destfile = "tempMtrl.html")
download.file(urlK,destfile = "tempKt.html")
library(XML)
Then we extract the tables with important informations
tables=readHTMLTable("tempKt.html")
TK=tables[[6]]
TK[] <- lapply(TK, function(col) {
if (is.character(col)) {
col <- gsub(",", ".", col)
col <- gsub("\\s", "", col)
}
suppressWarnings(as.numeric(col))
})
tables=readHTMLTable("tempMtrl.html")
TM=tables[[7]][,-1]
TM[] <- lapply(TM, function(col) {
if (is.character(col)) {
col <- gsub("\u2212", "-", col)
col <- gsub(",", ".", col)
col <- gsub("\\s", "", col)
}
suppressWarnings(as.numeric(col))
})
and we plot them
cols <- paste0("V", 2:13)
mois <- c("JAN","FEB","MAR","APR","MAY","JUN","JUL","AUG","SEP","OCT","NOV","DEC")
yminK <- suppressWarnings(as.numeric(TK[2, cols]))
ymaxK <- suppressWarnings(as.numeric(TK[3, cols]))
yminM <- suppressWarnings(as.numeric(TM[2, cols]))
ymaxM <- suppressWarnings(as.numeric(TM[3, cols]))
y0K <- pmin(yminK, ymaxK, na.rm = TRUE)
y1K <- pmax(yminK, ymaxK, na.rm = TRUE)
y0M <- pmin(yminM, ymaxM, na.rm = TRUE)
y1M <- pmax(yminM, ymaxM, na.rm = TRUE)
x <- seq_along(cols)
plot(NA,
xlim = c(0.5, length(cols) + 0.5),
ylim = range(y0M, y1M, y0K, y1K, na.rm = TRUE),
xaxt = "n", xlab = "", ylab = "",
main = "Temperatures min-max (°C, averages)")
axis(1, at = x, labels = mois)
w <- 0.8
for (i in x) {
if (!is.na(y0[i]) && !is.na(y1[i])) {
rect(i - w/2, y0K[i], i + w/2, y1K[i],
col = "lightblue", border = "steelblue", lwd = 1.2)
}
}
for (i in x) {
if (!is.na(y0[i]) && !is.na(y1[i])) {
rect(i - w/2, y0M[i], i + w/2, y1M[i],
col = "lightcoral", border = "firebrick", lwd = 1.2)
}
}
grid(nx = NA, ny = NULL, col = "gray85")
with Kyoto in blue, Montréal in red,
of course, we can do the same for humidity
or daylight
R-bloggers.com offers daily e-mail updates about R news and tutorials about learning R and many other topics. Click here if you're looking to post or find an R/data-science job.
Want to share your content on R-bloggers? click here if you have a blog, or here if you don't.