R leaflet color scheme not working -


i color code markers on map. unfortunately, markers black (circled in red, because black faded!)

enter image description here

what i'm looking for

color points based on percent_sep12_assets, i.e.

  • less 33% = red
  • between 33% , 66% = orange
  • more 66% = green

code

sep <- read.csv("31r_sep_assets_csv - copy.csv")  sub1 <- sep[grep("sep.12", names(sep))] sep$newcol <- 100*rowsums(sub1)/rowsums(sep[4:7])  # create new grouping variable percent_sep12_assets <- ifelse(sep[,8] <= 33, "less 33%", ifelse(sep[,8] >= 66, "more 66%", "between 33% , 66%"))  color_assets <- colorfactor(c("green","orange","red"),                                levels = percent_sep12_assets)  leaflet(data = sep[]) %>%    setview(lng = mean(sep$longitude), lat = mean(sep$latitude), zoom = 12) %>% addtiles()  %>%   addcirclemarkers(~longitude, ~latitude,  color = ~percent_sep12_assets, popup = ~as.character(paste(site, percent_sep12_assets , sep=", ")))  

dput(sep)

structure(list(site = structure(1:5, .label = c("staten island\\31r001",  "staten island\\31r002", "staten island\\31r003", "staten island\\31r004",  "staten island\\31r005"), class = "factor"), latitude = c(40.508874,  40.577256, 40.520825, 40.552373, 40.529697), longitude = c(-74.244048,  -74.100135, -74.211845, -74.195516, -74.187532), windows.sep.11 = c(63l,  174l, 11l, 85l, 163l), mac.sep.11 = c(0l, 1l, 4l, 0l, 0l), windows.sep.12 = c(124l,  185l, 9l, 75l, 23l), mac.sep.12 = c(0l, 1l, 32l, 1l, 0l), newcol = c(66.3101604278075,  51.5235457063712, 73.2142857142857, 47.2049689440994, 12.3655913978495 )), .names = c("site", "latitude", "longitude", "windows.sep.11",  "mac.sep.11", "windows.sep.12", "mac.sep.12", "newcol"), row.names = c(na,  -5l), class = "data.frame") 

thanks!

turns out had reference percent_sep12_assets within ~color_assets

corrected code snippit

leaflet(data = sep[]) %>%    setview(lng = mean(sep$longitude), lat = mean(sep$latitude), zoom = 12) %>% addtiles()  %>%   addcirclemarkers(~longitude, ~latitude,  color = ~color_assets(percent_sep12_assets),  popup = ~as.character(paste(site, percent_sep12_assets , sep=", "))) 

and output resembles this

enter image description here


Comments

Popular posts from this blog

javascript - Using jquery append to add option values into a select element not working -

Android soft keyboard reverts to default keyboard on orientation change -

jquery - javascript onscroll fade same class but with different div -