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

javascript - Using jquery append to add option values into a select element not working -

user interface - how to replace an ongoing process of image capture from another process call over the same ImageLabel in python's GUI TKinter -

javascript - Restarting Supervisor and effect on FlaskSocketIO -