Lowering the alpha value in an OSM map (R,mapping)
The most recent version of the code used in this page (which might be a little different from the one here) can be found here.
Working on a poster with my postdoc, a problem came up where we wanted to increase the transparency of a map downloaded (and plotted) with
OpenStreetMap, because the points we were plotting on it were not really visible. The solution is very simple. It goes without saying that you will need the
OpenStreetMap library installed.
The first thing to do is to create a function to add an alpha value to the hexadecimal colour codes used in the
OpenStreetMap library. Note that we assume an alpha value in [0,1].
Let us load a map of a small region in Winnipeg. We first need the coordinates of the upper left and lower right corners of the box we want to download.
We also need to specify a map type. We take a cute map type in which alpha effect is easy to see.
Download the map. For convenience, we store the tile colours.
Finally, we plot the maps for several values of alpha.
Here are a few examples. First, the unaltered map (with alpha=1).
Second, the map when alpha=0.5.
Finally, a very light map where alpha=0.1.