1

I am trying to use the openairmaps and leaflet in R to add pollution plots on top of a leaflet map. Now I have already done this before, and produced the outcome I wanted, but that was almost 6 months ago and now the same code and data is no longer working. I am not aware of updates to openairmaps and I've tried to dig and see if the addPolarMarkers code (which is the function throwing the error) has changed, but it doesn't seem like it?

My data is air pollution data with a variety of variables, and is too lengthy to reproduce entirely, but I will show a basic version:

date year month particle_size concentration wd ws LAT LON
01 2021 01 10.8 192830 180 5 42 -71
02 2021 01 6.4 45028 180 0 42 -71
03 2021 01 20.9 47293 310 2 42 -71
04 2021 01 295.2 33894 18 5 42 -71
05 2021 01 365.1 173628 270 7 42 -71
06 2021 01 49.2 102983 210 10 42 -71
07 2021 01 65.7 473628 180 9 42 -71

All of these values are numeric.

So the code is just creating a basemap and adding a polar plot from this site on top:

m <- leaflet() %>%
  addTiles() %>%  # Add default OpenStreetMap map tiles
  addMarkers(lng=data$LON, lat=data$LAT, popup="The birthplace of R")
m %>% addProviderTiles(providers$CartoDB.Voyager) %>% 
  addPolarMarkers(
    data,
    pollutant = "concentration",
    fun=openair::polarPlot,
    lng= "LON",
    lat= "LAT",
    #cols="jet",
    #d.icon=120,
    #popup="name",
    #limits = c(0, 50000)
  )

Every time I run this now I get this error:

Error in UseMethod("drop_na") : 
  no applicable method for 'drop_na' applied to an object of class "list"

I have tried to debug and this code goes wrong in the create_polar_marker() function within the addPolarMarker() function. For some reason the data input is a list of label & dummyvariable for create_polar_marker(). My understanding of how this functions under the hood is very minimal so I am not clear on how this was generated.

If anyone has any insight that would be SO helpful! Thank you!

1 Answer 1

0

Just to confirm, are you using version 0.8.1 of openairmaps? Based on the package website, it looks like there was a breaking change in the arguments of the addPolarMarkers() function that moves the data argument after pollutant, owing to the new use of the leaflet::getMapData() function.

This seems to be solved by explicitly naming the data argument in the function, as based on your sample data, the map renders (granted, a warning pops up that there's not enough data to plot, but I'm sure that won't be a problem in your real data set).

library(openairmaps)
library(leaflet)

df <- tibble::tribble(
  ~date, ~year, ~month, ~particle_size, ~concentration, ~wd, ~ws, ~LAT, ~LON,
  01,   2021,   01, 10.8,   192830, 180,    5,  42, -71,
  02,   2021,   01, 6.4,    45028,  180,    0,  42, -71,
  03,   2021,   01, 20.9,   47293,  310,    2,  42, -71,
  04,   2021,   01, 295.2,  33894,  18, 5,  42, -71,
  05,   2021,   01, 365.1,  173628, 270, 7, 42, -71,
  06,   2021,   01, 49.2,   102983, 210,    10, 42, -71,
  07,   2021,   01, 65.7,   473628, 180,    9,  42, -71
)

m <- leaflet() |>
  addProviderTiles("CartoDB.Voyager")

m |> addPolarMarkers(
  data = df,
  pollutant = "concentration",
  fun = openair::polarPlot,
  lng = "LON",
  lat = "LAT"
) 

Screenshot of leaflet map with empty directional analysis plot.

1
  • Oh my goodness I can't believe it was that easy, you don't even know how long I spent on this.. Thank you so much!!!!
    – bre123
    Commented Feb 29 at 20:58

Not the answer you're looking for? Browse other questions tagged or ask your own question.