79131996

Date: 2024-10-28 03:44:07
Score: 0.5
Natty:
Report link

I found an answer to a similar question here.

You can control the fields that display using the popup.vars argument of tm_dots, including when you're using colour to symbolise a variable. This takes TRUE/FALSE to plot all/none of the variables, or a character vector of the variables you want to show.

#data
dat2plot <- st_as_sf(dat, coords = c("long","lat"), crs=st_crs("EPSG:4326"), remove = FALSE) 

#simple plot
tm_shape(dat2plot) +
  tm_dots(col= "species", alpha=0.8,size = 0.1,
          id = "species", #show on hover
          popup.vars = c("status", "lat", "long")) #character vector of desired variables

The id argument sets what variable shows when hovering over a point.

This method also allows for renaming the variables in the popup:

tm_shape(dat2plot) +
  tm_dots(col= "species", alpha=0.8,size = 0.1,
          id = "species", #show on hover
          popup.vars = c("Status" = "status",
                         "lat",  "long"))

The second code snippet returns this map, showing the named variables.

Reasons:
  • Probably link only (1):
  • Long answer (-0.5):
  • Has code block (-0.5):
  • Low reputation (0.5):
Posted by: Simeon