0

I have managed to plot a map of London using tmap in R:

library(sf)
library(tmap)
library(dplyr)
library(OpenStreetMap)

qtm("London")        
tmap_mode("plot")
tm_shape(lnd) + 
  tm_polygons(alpha = 0.7, legend.show = FALSE) +   
  tm_basemap(server = c('OpenStreetMap'))

But now I want to overlay some different sized bubbles on top of this map to show the number of tweets that mention a particular train station. Here is an example of what I want the bubbles to look like:

enter image description here

My train station data is like this with the lat/long for each of the stations and the volume of tweets: https://filebin.net/emjnete8pf0ulxpe

When I load the stations data, I know I am meant to convert to an sf object (see below):

stations  <- read.csv("Stations_example.csv", header = TRUE, stringsAsFactors = FALSE)
stations1 <- st_as_sf(stations, coords = c('Long', 'Lat'), crs=4326)

After this I get stuck - I am not sure how to get this information on the map in the way I want it.

Can anyone help? I am not wedded to using tmap. If there is a solution using another R package, I am happy to give that a go (although, I cannot use ggmap due to having to sign up with a credit card).


UPDATE 18/12/2019:

Thanks to Spacedman for his suggestion. It didn't initially work when I kept the tm_polygons bit in. This seemed to do the trick:

qtm("London")       
tmap_mode("view")
tm_shape(stations1)+
  tm_bubbles(col = "red", size= "Volume", scale = .5) +
  tm_basemap(server = c('OpenStreetMap')) 
JassiL
  • 432
  • 1
  • 7
  • 24

1 Answers1

2

You need to add another layer on top of your existing tmap object using tm_shape and a function for how you want to draw that layer.

tm_shape(lnd) + 
  tm_polygons(alpha = 0.7, legend.show = FALSE) +   
  tm_shape(tweets) + 
  tm_bubbles(size="count") + 
  tm_basemap(server = c('OpenStreetMap'))

where tweets is your spatial object and counts is a column with the number of tweets at each point location.

Spacedman
  • 92,590
  • 12
  • 140
  • 224
  • Thanks so much. It was the ```tm_polygons``` bit that wasn't working for me. I posted what I ended up using in the original question. – JassiL Dec 18 '19 at 11:13