In RStudio, I cannot get the map created by the following tmap script to save to my working directory. When running the script prior to the tmap_save line, I receive no errors. However, when I run tmap_save, I receive the following error:
Error in tmap_save(st_map, filename = mapname) :
Unknown format. tm should be either a tmap output, or a list of tmap outputs
There are six values for the looping variable (TimePeriod), so I am expecting 6 layers in the map.
Here is my script:
# Map Title
map_title <- paste(agency,'Place Schedule Adherence Map:',bookref,schedule, sep=' ')
# Initialize Map
tmap_mode("plot")
st_map <- NULL
# Loop Through Each Time Period
for (tp in tp_list) {
st_map <= st_map %>%
tm_shape(st_places %>% filter(TimePeriod == tp)) +
tm_symbols(col='AvgePgrDelay',
size=.01,
scale=10,
palette = 'YlOrRd',
group = paste(tp, 'Place Schedule Adherence'),
interactive=TRUE,
popup.vars=c('Booking',
'ScheduleType',
'TimePeriod',
'Place',
'StopID',
'StopName',
'Routes',
'Observations',
'PctEARLY',
'AvgeMinutesEARLY',
'PctONTIME',
'AvgeMinutesONTIME',
'PctLATE',
'AvgeMinutesLATE',
'AvgePgrDelay'))
}
# Add Map Title and Scale Bar
st_map <- st_map %>%
tm_layout(title = map_title,
title.size = 10,
title.fontface = 'bold')
# Create Map html File
mapname = paste0(agency,
' - Place Schedule Adherence Map - ',
bookref, ' - ',
schedule,
'.html', sep = '')
# Create Map html File
tmap_save(st_map, filename = mapname)
Thanks for any assistance that you may be able to provide!
I tried running it without the tm_layout command, but still got the same error message.
wbm is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.