I'm using lapply and update
to create a series of colors to include in a series of ggplot
pop-ups. The plots are to appear in a leaflet
map, as demonstrated here. What is the "need an object with call component" error all about, and how do I resolve it?
x<-structure(list(FacilName = c("ALL ABOU", "ANITA BR", "RAINBOW ", "RANEY DA", "CAS DONO", "A HOME A", "COURT TI", "ECONOMY "),
lon = c(-79.8466921, -79.9265183, -80.240089, -79.7807676, -79.8687159, -79.8064845, -79.8527703, -80.2034522),
lat = c(40.5808574, 40.2919276, 40.6674307, 40.5880096, 40.1815023, 40.3850284, 40.2577138, 40.6867816),
HC01_VC04 = c(4370L, 7700L, 1056L, 584L, 2318L, 1029L, 5053L, 4202L),
HC01_VC87 = c(0L, 0L, 0L, 0L, 31L, 0L, 6L, 22L),
IDnum = c("11", "12", "13", "14", "15", "16", "17", "18")), row.names = 11:18, class = "data.frame")
p<-ggplot(x, aes(HC01_VC87,HC01_VC04))+geom_point() # construct a basic plot
p<-mget(rep("p",length(x$FacilName))) # create a set of plots to pop-up in map with `mget`
clr <- rep("orange", length(x$FacilName)) # default color in scatterplot
# create points that indicates specific facility when popup opens
# error occurs here
p <- lapply(1:length(p), function(i) {
clr[i] <- "dark green"
update(p[[i]], col = clr) })
# map this (will throw error because previous command throws error)
library(leaflet);library(mapview)
leaflet() %>% addTiles()%>%
addCircleMarkers(data=x,label=x$FacilName,
weight = .4,fillOpacity = 1,radius = 4,
popup = popupGraph(p))