rggplot2leafletggmapopenair

Overlay plot on map background in R


I want to make a windrose plot on a specific location. Windrose can be plot with openair package

library(openair)
windRose(mydata, "ws", "wd")

or with ggplot using this function. What I am looking for, a nice way to overlay this plot on a map. I tried with ggmap (I don't have a google map API key) and leaflet. This example also I tried, the output is below. enter image description here

Is there a way to overlay ggplot on leaflet map or any other ggmap way to do it nicely.


Solution

  • That is a multi-step process and will take a bit of tweaking to make it work the way you want but it can be done in 3 steps.

    Set the background of your chart to transparent

    Save a png locally

    Use addLogo() from mapview package to post the image to your map and place it

    For sure you will need to problem solve some as you implement this process. If you are doing this in Shiny you would want to use directory management to create and destroy the plots as data updates and be sure to make the creation of the graph reactive or observed in some way.

    If you are making a nice rMarkdown dashboard, just make sure you keep track of where the png file saves and use the proper addressing.