TransWikia.com

Changing tmap custom icon/symbol size within legend

Geographic Information Systems Asked by geoscience123 on July 2, 2021

Continuing a question from here: Adding tmap_icon to legend in r

The answer provided shows how to add a custom PNG image to a tmap in R, however, I now looking for a way to increase the symbol size within the tmap legend. See below:

library(tmap)
library(sf)
#> Linking to GEOS 3.8.1, GDAL 3.1.4, PROJ 6.3.1
library(tidyverse)



tdir=tempdir()
Stateshpurl= "https://www2.census.gov/geo/tiger/GENZ2018/shp/cb_2018_us_state_5m.zip"
if(file.exists(paste(tdir,"/cb_2018_us_county_5m/cb_2018_us_county_5m.shp",sep=""))==FALSE){
  download.file(Stateshpurl, destfile = file.path(tdir,"State_Boundaries.zip"))
  unzip(file.path(tdir,"State_Boundaries.zip"),exdir = tdir)}
US_states=read_sf(paste(tdir,"/cb_2018_us_state_5m.shp",sep=""))

US_states = st_transform(US_states, 5070) 

L48 = US_states %>%
  filter(STATEFP != "02") %>%
  filter(STATEFP != "15") %>%
  filter(STATEFP != "60") %>%
  filter(STATEFP != "64") %>%
  filter(STATEFP != "66") %>%
  filter(STATEFP != "68") %>%
  filter(STATEFP != "69") %>%
  filter(STATEFP != "70") %>%
  filter(STATEFP != "72") %>%
  filter(STATEFP != "74") %>%
  filter(STATEFP != "78")

icon_url="http://29.media.tumblr.com/tumblr_m0q2g8mhGK1qk6uvyo1_500.png"
download.file(icon_url, destfile = file.path(tdir,"Image.png"),mode = 'wb')

L48$icon = "my label"
Icon=tmap_icons(file=paste(tdir,"/Image.png",sep=""))

tm_shape(L48)+
  tm_borders()+
  tm_symbols(shape = "icon", shapes = Icon,
             title.shape = "My icon")

Notably, the size = argument only changes the size of the icon within the map space itself.

Add your own answers!

Ask a Question

Get help from others!

© 2024 TransWikia.com. All rights reserved. Sites we Love: PCI Database, UKBizDB, Menu Kuliner, Sharing RPP