0

I am using Rstudio on my macbook, I want to run a geographical analysis. I have the leaflet library, and the required libraries overall. However, when i View(make_a_map) there is not a visual but name, type and value.

I tried:

make_a_map <- leaflet(bike_ride) %>%
  addTiles() %>%
  addMarkers(~start_lat, ~start_lng, popup = ~start_station_name)

View(make_a_map)

I was expecting an interactive map.

1 Answer 1

1

Rather than View(make_a_map) have you tried making the last line simply make_a_map? It looks like make_a_map is already a leaflet object and just needs to be displayed by calling it directly (see example below).

Find what a function does by typing ?FUNCTION_NAME in the R command prompt. For example, ?View brings up the help which says that View() invokes a spreadsheet-style data viewer on a matrix-like R object. It is for looking at data frames rather than maps.

The leaflet library offers examples of how to construct interactive map visualizations.

library(leaflet)

m <- leaflet() %>%
  addTiles() %>%  # Add default OpenStreetMap map tiles
  addMarkers(lng=174.768, lat=-36.852, popup="The birthplace of R")
m  # Print the map

Note how m is assigned to a leaflet() object and then simply called in the last line of the code chunk.

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