library(wikilake)
## Loading required package: maps
WikipediR::page_info("en", "wikipedia",
res <-page = "Category:Lakes of Michigan")
xml2::read_html(res$query$pages[[1]]$canonicalurl)
res <- rvest::html_nodes(res, "#mw-pages .mw-category")
res <- rvest::html_nodes(res, "li")
res <- rvest::html_nodes(res, "a")
res <- rvest::html_attr(res, "title") res <-
res[!(seq_len(length(res)) %in% grep("List", res))]
res <- res[!(seq_len(length(res)) %in% grep("Watershed", res))]
res <- res[!(seq_len(length(res)) %in% grep("lakes", res))]
res <- res[!(seq_len(length(res)) %in% grep("Mud Lake", res))] res <-
lapply(res, lake_wiki)
res <-
# remove missing coordinates
res[unlist(lapply(res, function(x) !is.na(x[, "Lat"])))] res <-
data.frame
unique(unlist(lapply(res, names)))
res_df_names <- data.frame(matrix(NA, nrow = length(res),
res_df <-ncol = length(res_df_names)))
names(res_df) <- res_df_names
for (i in seq_len(length(res))) {
data.frame(matrix(NA, nrow = 1,
dt_pad <-ncol = length(res_df_names) - ncol(res[[i]])))
names(dt_pad) <- res_df_names[!(res_df_names %in% names(res[[i]]))]
cbind(res[[i]], dt_pad)
dt <- dt[, res_df_names]
dt <- dt
res_df[i, ] <- }
library(sp)
coordinates(res_df) <- ~ Lon + Lat
map("state", region = "michigan", mar = c(0, 0, 0, 0))
points(res_df, col = "red", pch = 19)
hist(log(res_df$`Max. depth`), main = "", xlab = "Max depth (log(m))")