TopoJSON choropleth in R / Leaflet?

Is it possible to create a TopoJSON file from its functions for choropleth using R / flyers? I tried several things, and I'm not sure if this is not possible with the package leafletor if I just don't have the syntax on the right, especially for accessing the properties that need to be entered into the function pal(). Here is what I have:

pal<-colorNumeric(palette ="YlOrRd",domain = USAdata$GINI) #USAdata data frame I merged with the spdf before converting it to shp/topojson

map<-leaflet() %>% 
  addTiles(options=tileOptions(minZoom = 3)) %>% 
  setMaxBounds(-167.276413,5.499550,-52.233040, 83.162102) %>%
  setView(93.85,37.45,zoom =3) %>%
  #addGeoJSON(geojson = jso5)
  addTopoJSON(topojson=jso, fillColor = ~pal("GINI"))
#addPolygons(data=poly)

this causes an error:

"Error in UseMethod("doResolveFormula") : 
  no applicable method for 'doResolveFormula' applied to an object of class "NULL""

I also tried converting it to an R topojson object using the JSON () method and adding style elements, but this will not load after I try to send it back using the jSON () function.

Not sure which is relevant, but topojson was created from a shapefile made in accordance with the instructions here :

with cl:

topojson -o 'USApuma.json' --shapefile-encoding utf8 --id-property=+GEOID10 -p GINI,+STATEFP10,+GEOID10 -- 'usaetest.shp'

then enter readLines().

. .

+4
1

TopoJSON? tigris (: ). , , . , . , PUMAs :

library(readr)
library(tigris)
library(leaflet)

us_states <- unique(fips_codes$state)[1:51]

continental_states <- us_states[!us_states %in% c("AK", "HI")]

pumas_list <- lapply(continental_states, function(x) {
  pumas(state = x, cb = TRUE)
})

us_pumas <- rbind_tigris(pumas_list)

, PUMA ; geo_join tigris us_pumas:

puma_income <- read_csv('http://personal.tcu.edu/kylewalker/data/puma_income.csv')

joined_pumas <- geo_join(us_pumas, puma_income, 'GEOID10', 'GEOID')

:

pal <- colorQuantile(palette = 'YlOrRd', domain = joined_pumas$hhincome, n = 7)

leaflet(joined_pumas) %>% 
  addProviderTiles('CartoDB.Positron') %>% 
  addPolygons(weight = 0.5, fillColor = ~pal(hhincome), 
              color = 'lightgrey', fillOpacity = 0.75, 
              smoothFactor = 0.2) %>% 
  addLegend(pal = pal, 
            values = joined_pumas$hhincome)

Average PUMA Family Income

"", PUMAs, tigris, .rda Shiny script, rbind_tigris .

+1

Source: https://habr.com/ru/post/1619681/


All Articles