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 transformating 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)
#> Warning: Removed 231 rows containing missing values (geom_point).