NOT_CRAN <- identical(tolower(Sys.getenv("NOT_CRAN")), "true")
knitr::opts_chunk$set(
  collapse = TRUE,
  comment = "#>",
  purl = NOT_CRAN,
  eval = NOT_CRAN
)

In this vignette I want to plot a map of the world with points to represent monitors whose data is available on the platform. However there are not geographical coordinates for all locations so the map will not be exhaustive.

Loading packages. Note that an even nicer map could be drawn with the R package OpenStreetMaps which requires the rJava package.

library("ggplot2")
library("ropenaq")
library("dplyr")

Getting coordinates and transforming it.

create a list to hold output

For now I'm filtering out two stations with surprising coordinates.

dataGeo <- aq_locations()
dataGeo <- filter(dataGeo, location != "Test Prueba", location != "PA")

Getting the empty map.

library("rworldmap")

worldMap <- map_data(map="world")

gg <- ggplot() + geom_map(data=worldMap, map=worldMap,
                          aes(map_id=region, x=long, y=lat),
                          fill = "grey60")
gg

Map with monitors.

plotMap <- gg +
  geom_point(data = dataGeo, aes(x=longitude, y=latitude), size=1, col = "#EE9F8E")+
  theme(axis.line=element_blank(),axis.text.x=element_blank(),
       axis.text.y=element_blank(),axis.ticks=element_blank(),
       axis.title.x=element_blank(),
       axis.title.y=element_blank(),legend.position="none",
       panel.background=element_blank(),panel.border=element_blank(),panel.grid.major=element_blank(),
       panel.grid.minor=element_blank(),plot.background=element_blank())+
   ggtitle("OpenAQ data sources with geographical coordinates") +
  theme(plot.title = element_text(lineheight=1, face="bold"))
print(plotMap)


ropenscilabs/ropenaq documentation built on May 18, 2022, 8:31 p.m.