Hello, I have been using leaflet to create maps for a project.
Recently I have gotten the issue "Error in validateCoords(lng, lat, funcName) : addCircleMarkers requires numeric longitude/latitude values"
My data does have longitude and latitude values, so I was wondering if anyone knew of how to fix this issue.
My code is:
library(leaflet)
library(tidyverse)
library(farver)
library(dplyr)
library(stringr)
library(RColorBrewer)
#Set working directory and import data
setwd("/Users/JohnDow/Desktop/RStudioMap")
Data<-read.csv("FinalR2.csv", stringsAsFactors=F)
#Subset data by MSI category
HSI <- Data %>% filter(Data$MSI.category =="HSI")
HBCU <- Data %>% filter(Data$MSI.category =="HBCU")
TCU <- Data %>% filter(Data$MSI.category =="TCU")
Fed <- Data %>% filter(Data$MSI.category =="Federal Institution")
Ind <- Data %>% filter(Data$MSI.category =="Industry")
Academ <- Data %>% filter(Data$MSI.category =="Non-MSI Academic Institution")
np <- Data %>% filter(Data$MSI.category =="Non-Profit")
prof <- Data %>% filter(Data$MSI.category =="Professional Society")
none <- Data %>% filter(Data$MSI.category =="No MSI Catagory")
AANAPISI <- Data %>% filter(Data$MSI.category =="AANAPISI")
NASACenter <- Data %>% filter(Data$MSI.category == "NASA Center")
hsi_loc <-select(HSI, Institution, Lat, Long, City, State, Country, MSI.type, MSI.category)
hbcu_loc <-select(HBCU,Institution, Lat, Long, City, State, Country, MSI.type, MSI.category)
tcu_loc <-select(TCU, Institution, Lat, Long, City, State, Country, MSI.type, MSI.category)
Ind_loc <-select(Ind, Institution, Lat, Long, City, State, Country, MSI.type, MSI.category)
fed_loc <-select(Fed, Institution, Lat, Long, City, State, Country, MSI.type, MSI.category)
Academ_loc <-select(Academ, Institution, Lat, Long, City, State, Country, MSI.type, MSI.category)
np_loc <-select(np, Institution, Lat, Long, City, State, Country, MSI.type, MSI.category)
prof_loc <-select(prof, Institution, Lat, Long, City, State, Country, MSI.type, MSI.category)
n_loc <-select(none, Institution, Lat, Long, City, State, Country, MSI.type, MSI.category)
a_loc <-select(AANAPISI, Institution, Lat, Long, City, State, Country, MSI.type, MSI.category)
nasa.center_loc <-select(NASACenter, Institution, Lat, Long, City, State, Country, MSI.type, MSI.category)
md <-rbind(hsi_loc, hbcu_loc,tcu_loc, n_loc, Academ_loc, fed_loc, Ind_loc,prof_loc,np_loc, a_loc)
#factpal <- colorFactor(topo.colors(7), md$MSI.type)
#factpal <- colorFactor(brewer.pal(n = 7, name = "Dark2"), md$MSI.type)
factpal <- colorFactor(brewer.pal("Set1", n = 7), md$MSI.type)
#factpal <- colorFactor(brewer.pal("Paired", n = 7), md$MSI.type)
loc <- paste(md$City,md$State,md$Country, sep = ", ") #Returns "City, ST, Country"
bold.ins <- paste("<b><font color=\"#284D8E\">",md$Institution,"</font></b>")
content <- paste(sep = "<br/>",
bold.ins,
loc,
md$MSI.category
)
m<- leaflet(md)%>%
addTiles('http://{s}.basemaps.cartocdn.com/dark_all/{z}/{x}/{y}.png')%>%
setView(-97.655210, 30.324303, zoom = 4) %>%
addCircleMarkers(~Long, ~Lat, popup=content, weight = 3, radius= (~ifelse(MSI.type == "NASA Center", 4.5, 4.5)), color=~factpal(MSI.type), stroke = F, fillOpacity = 1)%>%
addLegend("bottomright", pal = factpal, values = ~MSI.type, title = "Categories")
m
Any help is appreciated.