r - understanding ggplot2 geom_map map_id -


this comes ggplot2 documentation:

# better example crimes <- data.frame(state = tolower(rownames(usarrests)), usarrests) library(reshape2) # melt crimesm <- melt(crimes, id = 1) if (require(maps)) {   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)   last_plot() + coord_map()   ggplot(crimesm, aes(map_id = state)) + geom_map(aes(fill = value), map = states_map) + expand_limits(x = states_map$long, y = states_map$lat) + facet_wrap( ~ variable) } 

i don't understand how can work since there no common identifier in states_map data frame uses "region" name states column , crimes data frame labels states, "states." ties data map?

in example poster renames columns of map data frame conform data ggplot2 documentation doesn't seem it. how? when rename columns of states_map in example above, "state" common both data frames, breaks code.

crimes <- data.frame(state = tolower(rownames(usarrests)), usarrests) library(reshape2) # melt crimesm <- melt(crimes, id = 1) if (require(maps)) {   states_map <- map_data("state") ##### attempt fix isn't broken ################# names(states_map)[5]<-"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)   last_plot() + coord_map()  # error: all(c("x", "y", "id") %in% names(map)) not true } 

thanks.


Comments

Popular posts from this blog

Android : Making Listview full screen -

javascript - Parse JSON from the body of the POST -

javascript - Chrome Extension: Interacting with iframe embedded within popup -