I am trying to move from older ways of matching data with choropleth, now that ggplot2 has geom_map. An example is shown on pages 10-11 ( HERE ).
I am trying to do this with a dataset that I created choropleth from the past, and not with ggplot new geom_map. Here, my attempt, I think, is similar to the Hadely example, but all the colors are the same color.
Dataset and code:
load(url("http://dl.dropbox.com/u/61803503/MAPPING.RData"))
library(ggplot2)
ggplot(cad, aes(map_id = subregion)) +
geom_map(aes(fill = Math_Pass_Rate), map = ny) +
expand_limits(x = ny$long, y = ny$lat) +
guides(fill = guide_colorbar(colours = topo.colors(10))) +
opts(legend.position = "top")
Why is it displayed as a single color?
Additional information from @PaulHiemstra
I am a little puzzled and cannot get a good result. However, I also wonder why the example from ggplot2 pdf that you link to works.
This code creates the correct choropleth map.
crimes <- data.frame(state = tolower(rownames(USArrests)), USArrests)
states_map <- map_data("state")
ggplot(crimes, aes(map_id = state)) +
geom_map(aes(fill = Murder), map = states_map) +
expand_limits(x = states_map$long, y = states_map$lat) +
guides(fill = guide_colorbar(colours = topo.colors(10))) +
opts(legend.position = "top")
, , map_id = state, states_map () crimes (Murder). crimes state:
> head(crimes)
state Murder Assault UrbanPop Rape
Alabama alabama 13.2 236 58 21.2
Alaska alaska 10.0 263 48 44.5
Arizona arizona 8.1 294 80 31.0
Arkansas arkansas 8.8 190 50 19.5
California california 9.0 276 91 40.6
Colorado colorado 7.9 204 78 38.7
states_map :
> head(states_map)
long lat group order region subregion
1 -87.46201 30.38968 1 1 alabama <NA>
2 -87.48493 30.37249 1 2 alabama <NA>
3 -87.52503 30.37249 1 3 alabama <NA>
4 -87.53076 30.33239 1 4 alabama <NA>
5 -87.57087 30.32665 1 5 alabama <NA>
6 -87.58806 30.32665 1 6 alabama <NA>
, - . , @TylerRinker.