Reputation: 127
I'm trying to plot using leaflet with a somewhat sizable set of coordinates (~34K latitude/longitude pairs) however, using the code below it seems that leaflet is only plotting a small portion of these:
data <- read.csv("Food_inspections.csv", header = TRUE)
names(data) <- tolower(names(data))
data1 <- filter(data, risk == c("Risk 1 (High)","Risk 2 (Medium)","Risk 3 (Low)"))
data1$risk <- droplevels(data1$risk)
leaflet(data1) %>%
addTiles() %>%
addMarkers(lat = ~latitude, lng = ~longitude)
What I get back is a map like this:
This clearly does not contain all ~34K coordinates. Even if I use "addCircles" I get the same thing. Other mapping packages (RgoogleMaps for instance) seem to plot everything correctly. Does leaflet round the coordinates it takes as input before plotting because I could see that making several of the coordinates appear to overlap in the plot.
Upvotes: 1
Views: 1574
Reputation: 6659
The points are there, you have to zoom in to see them. But... at least in my browser... anything more than 80 points or so, and it takes super long to zoom.
url <- "http://data.cityofchicago.org/api/views/4ijn-s7e5/rows.csv?accessType=DOWNLOAD"
data <- read.csv(url, header = TRUE) # takes a minute...
names(data) <- tolower(names(data))
data1 <- subset(data, risk %in% c("Risk 1 (High)","Risk 2 (Medium)","Risk 3 (Low)"))
data1$risk <- droplevels(data1$risk)
data1 <- data1[1:50,]
library(leaflet)
leaflet(data1) %>%
addTiles() %>%
addMarkers(lat = ~latitude, lng = ~longitude)
Upvotes: 2