Creating a tilemap with custom shortcuts in R

I would like to visualize my data using a world map in R, where labels have to be added at specific points (given coordinates). Labels should have 3D rectangles with a height proportional to the value from the datasheet. I would use the R-package booklet (or any alternative if better). There are about 10-15 points around the world, and there are two values ​​for each location (in particular, points are the locations of large oil fields, and the values ​​are, for example, sizes and reserves). I want to have two such 3D rectangles for each point, say red and blue, standing next to each other, with corresponding heights and numbers on them, and each point should be labeled with the name of the oil field. I found a solution with the leaflet package by adding circles to the map with the appropriate radius.

Data and libraries are loaded by code:

library(leaflet)
basins<-read.csv("somedata.csv")

      

And somedata.csv has the following structure (four datalines just as a minimal working example):

basin,lat,lon,res.density,rel.area
Central Sumatra,1,96,16.7,75
North Sea,58.4,2,20,24
Maracaibo basin,9,-71,74.4,14.3
Los Angeles,33,-118,31.2,32

      

The circled card is called by the command

m=leaflet(data = basins) %>% addTiles() %>% addCircleMarkers(~lon, ~lat , popup = ~as.character(basin),radius=~res.density*0.4,label=~htmlEscape(basin),labelOptions=labelOptions(noHide=T,textOnly=TRUE,direction="bottom"))

      

However, this solution is not that good as it prevents the second value from being rendered (via the argument radius = ~ res.density, where res.density is the name of the first value for the pool in my .csv table).

I would like to reproduce something similar to this image that was generated by GMT. It is sufficient to have an equal (2D) map, however for each point you need two such rectangles with the field name and values ​​for each rectangle.

Image from package GMT

enter image description here

+3


source to share


1 answer


You can add a histogram using a package leaflet.minicharts

like this:

library("leaflet")
library("htmltools")
library("leaflet.minicharts")

basins <- read.table(text="basin,lat,lon,res.density,rel.area
Central Sumatra,1,96,16.7,75
North Sea,58.4,2,20,24
Maracaibo basin,9,-71,74.4,14.3
Los Angeles,33,-118,31.2,32", header=T, sep=",")

leaflet(data = basins) %>% 
  addProviderTiles("OpenStreetMap.Mapnik") %>% 
  addLabelOnlyMarkers(lng = ~lon, lat = ~lat, label = ~htmlEscape(basin),
                      labelOptions = labelOptions(noHide = TRUE, textOnly = TRUE, 
                                                  direction = "bottom", offset = c(0,5))) %>%
  addMinicharts(basins$lon, basins$lat, type = "bar", 
                chartdata = basins[, c("res.density", "rel.area")], width = 50, height = 60)

      



Perhaps you can leave addCircleMarkers for simplicity.

enter image description here

+7


source







All Articles