jbkunst / r-posts

Some R scripts and some R ideas
http://jkunst.com/
Apache License 2.0
50 stars 15 forks source link

Applying example to just a map of Alabama #2

Closed Edge363 closed 8 years ago

Edge363 commented 8 years ago

Hello! Thank you so much for this amazing library. I think you probably have the best R to javascript library on the market right now. I was recently trying to apply your example to just a map of Alabama, but I run into a problem whenever I try. I was able to modify the data so that it only includes Alabama counties, but I really want to be able to have a geojson of just Alabama. I found one at http://code.highcharts.com/mapdata/countries/us/us-al-all.js The problem is I can't swap out the maps because I have no idea how the data("uscountygeojson") method works, I looked through the hcharts index, but again I cannot figure out how to load in the data from that URL. Can you please help me by describing how to massage/read the data so it can be used in Highcharter?

jbkunst commented 8 years ago

Hi @Edge363 ,

Thanks for your words,

Is not a good choice start from uscountygeojson. It's easier if you found a geojson only for alabama, for example http://lmgtfy.com/?q=alabama+geojson.

Now, we have our json url so, a one way to chart alabama is:

url <- "http://catalog.civicdashboards.com/dataset/1c992edf-5ec7-456b-8191-c73a33bb79e1/resource/af46d2c0-5f84-42ae-85a1-d2ab7d46d9a7/download/ee2d088c0afb441cb8eaf57a8d279de6temp.geojson"

geojsonlist <- url %>% 
  readLines %>% 
  fromJSON(simplifyVector = FALSE)

highchart(type = "map") %>% 
  hc_add_series(mapData = geojsonlist,
                nullColor = "#425668",
                showInLegend = FALSE)
jbkunst commented 8 years ago

I'll close the issue, if you have more question dont doubt to ask in stack overflow ;)!