r - ggplot2 mapping county boundries in one color and state boundries in another on the same map -


i creating choropleth county map grey borders, , want include state boundries in black. know how go adding second layer of state mapping existing county map?

here's data set , code ended using:

#load libraries     library(ggplot2)     library(ggmap)     library(maps)     library(plyr)  #get wif file wip <- read.csv("wip.csv")   #get map data counties , states county_map <- map_data("county") state_map <- map_data("state")  #merge wip , county_map wip_map <- merge(county_map, wip, by.x=c("region", "subregion"),      by.y=c("region","subregion"), all.x=true)  #resort merged data wip_map <- arrange(wip_map, group, order)  #relpace na 0's wip_map[is.na(wip_map)] <- 0  #generate disctrete color pallette     pal <- c("#f7fcf5","#74c476","#41ab5d","#238b45","#006d2c","#00441b")   theme_clean <- function(base_size = 12) {     require(grid)     theme_grey(base_size) %+replace%     theme(         axis.title      =   element_blank(),         axis.text       =   element_blank(),         panel.background    =   element_blank(),         panel.grid      =   element_blank(),         axis.ticks.length   =   unit(0,"cm"),         axis.ticks.margin   =   unit(0,"cm"),         panel.margin    =   unit(0,"lines"),         plot.margin     =   unit(c(0,0,0,0),"lines"),         complete = true         )     }  final_map <- ggplot(wip_map, aes(x=long, y=lat, group=group, fill=factor(category))) +             geom_polygon(colour="grey", aes(fill=factor(category))) +             scale_fill_manual(values=pal) +             expand_limits(x = wip_map$long, y = wip_map$lat) +             coord_map("polyconic") +              labs(fill="number per\ncounty") +                  theme_clean()   final_map + geom_path( data = state_map , colour = "red") 

thanks!

just add geom_path code...

i used red highlight boundaries can set black.

    ggplot( wip_map, aes( x = long , y = lat , group=group ) ) +         geom_polygon( colour = "grey" , aes( fill = factor( category ) ) ) +         scale_fill_manual( values = pal ) +         expand_limits( x = wip_map$long, y = wip_map$lat ) +         coord_map( "polyconic" ) +          labs(fill="number per\ncounty") +          theme_clean( ) +         geom_path( data = state_map , colour = "red") 

enter image description here


Comments

Popular posts from this blog

SPSS keyboard combination alters encoding -

Add new record to the table by click on the button in Microsoft Access -

javascript - jQuery .height() return 0 when visible but non-0 when hidden -