When I try to display point data using tm_symbols
, I get the error message:
non-numeric argument to binary operator
.
I have stripped my code back to try to pinpoint the problem, and of course I have searched the tmap
and other documentation.
Some links to other people doing something like what I am trying to do:
- https://stackoverflow.com/a/45484314/5168907
- https://stackoverflow.com/a/52951856/5168907
- https://www.rdocumentation.org/packages/tmap/versions/2.2/topics/tm_symbols
See also:
Here's my reprex:
library(sf)
library(tmap)
library(leaflet)
item_data <- data.frame(
name=c("Epping Forest District Citizens Advice (Epping)","Epping Forest District Citizens Advice (Loughton)","Epping Forest District Citizens Advice (Waltham Abbey)"),
latitude=c("51.696921", "51.649158", "51.687181"),
longitude=c("0.110474", "0.05899", "-0.004736"),
stringsAsFactors = FALSE
)
items_sf <- st_as_sf(item_data, coords=c("longitude", "latitude"), crs=3857)
tmap_mode("view")
epmap <- tm_basemap(leaflet::providers$Stamen.TonerBackground) +
tm_shape(items_sf, name="CA Locations") +
tm_symbols(shape=21)
epmap
This gives me:
## Error in b[3:4] - b[1:2] : non-numeric argument to binary operator
I'm trying to use tmap
as I have seen it recommended, but I thought I'd also try different ways of generating the map instead... If I do:
plot(items_sf)
...it gives the error:
## Error in r[i1] - r[-length(r):-(length(r) - lag + 1L)] : non-numeric argument to binary operator
and if I do:
library(mapview)
mapview(items_sf)
... I get a mapview with the three points plotted but at a scale of less than a metre, total extent, so the coords are not being processed as lat and lon for some reason.
I am happy to work on solving problems but I think I am really stuck here because I have no idea what to do with these error messages.
I am expecting a tmap plot of the three locations as points (dots/symbols) overlaid onto the basemap. Actual results: error messages and no map rendered.
** Edit : well, the quoting numerics error was pretty stupid of me, good spot by the respondent. Caused by me typing out the data frame rather than simply copying from the one I was actually using. Once that was fixed I still had some other errors with my script but i got them fixed eventually.
The projection/ESPG thing was helpful because I don't really understand those yet and was basically guessing what to do. So I learned something there, too. **