Skip to content

Instantly share code, notes, and snippets.

@ajschumacher
Last active August 29, 2015 13:58
Show Gist options
  • Save ajschumacher/10312842 to your computer and use it in GitHub Desktop.
Save ajschumacher/10312842 to your computer and use it in GitHub Desktop.
figuring out state key names, or other problem
test <- data.frame(state=c("Florida", "Virginia", "Texas", "California",
"Georgia", "North Carolina", "New York",
"Missouri", "Illinois", "Maryland", "Pennsylvania",
"Tennessee", "Colorado", "Washington", "Arizona",
"Ohio", "Wisconsin", "District of Columbia",
"Michigan", "New Jersey", "Utah", "Louisiana",
"Minnesota", "Alabama", "Kansas", "Massachusetts",
"Indiana", "South Carolina", "Arkansas", "Oregon",
"Nevada", "Kentucky", "Nebraska", "(not set)",
"Connecticut", "New Mexico", "Oklahoma",
"West Virginia", "Iowa", "Hawaii", "Rhode Island",
"Mississippi", "Maine", "New Hampshire", "Delaware",
"Alaska", "Idaho", "North Dakota", "Vermont",
"Montana", "South Dakota", "Wyoming"),
value1=rnorm(52),
value2=rnorm(52))
library(rMaps)
crosslet(x="state",
y=c("value1", "value2"),
data=test,
map="us")
@ramnathv
Copy link

ramnathv commented Apr 9, 2014

The default maps use abbreviated state names as keys. So just do

test = transform(test, state_abb = state.abb[match(state, state.name)])
crosslet(
  x = "state_abb",
  y = c("value1", "value2"),
  data = test,
   map = "us"
)

@ajschumacher
Copy link
Author

@ramnathv Thanks, that should get this closer to working - but it still isn't working. :(

Ah! Looking at the HTML that gets generated, it looks like it's trying to pull in topo json for US counties - I don't think that even has the states in it by themselves! Right? Do I just need to find topo json for the states?

@ramnathv
Copy link

Yes. You do need topojson for US states. Let me know if you are able to get it working or hit another bottleneck.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment