So far, I've managed to visually present data for different socio-economic factors at a district level in Pakistan with the help of the tmap package in RStudio to create the following output.

Electricity in Schools

At the same time, I have used the ggmap package to plot the geographic co-ordinates of various towers for different Mobile Network Operators in Pakistan (roughly 13000 towers). The output is as follows.

Towers in Pakistan

My next requirement is to overlay the second plot over the first, essentially showing the towers on top of the district wise electricity scores.

Any ideas on which packages I could use (as well as sample code) in order to achieve this?


2 Answers 2


This can also be done with tmap. Have a look at the tmap vignette, especially the Plotting with tmap elements section.

In your case your code ought to look basically like this:

tm_shape(shapefile_with_electricity_data) + 
  tm_fill("Electricity_in_Schools_variable") + 
tm_shape(shapefile_with_MNO_data) + 

You can try the st_as_sf function from the sf package.

I used it in one of my project:

boston <- st_read("../data/boston.geojson")
proj4 <- st_crs(boston)$proj4string

student_points <- student_info %>% 
   st_as_sf(coords = c('lng', 'lat'), crs = proj4)

tm_shape(boston) +
  tm_polygons('#f0f0f0f0', border.alpha = 0.2) +
tm_shape(student_points_rastered) +
  tm_raster(alpha = 0.7, title = '# of students')

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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