How to fill individual states on a map in R? -


i create of padd areas of in r bottom part of canada. possible?

i keep labels, , have states highlighted based on padd. tried looking example online couldn't find it.

library(maps)  map("state", interior = false)  map("state", boundary = false, col="gray", add = true) 

this missing state labels, colour , bottom part of canada.

enter image description here

thanks, i'm able shading sort of work after fill in 1 padd next fills in past padds. also, still add bottom part canada mix. lastly i'm getting error when adding text lables.

for table of padds , states:

padds<-structure(     list(state = structure(1:50,                            .label = c("alabama", "alaska", "arizona", "arkansas", "california", "colorado", "connecticut", "delaware", "florida", "georgia", "hawaii", "idaho", "illinois", "indiana", "iowa", "kansas", "kentucky", "louisiana", "maine", "maryland", "massachusetts", "michigan", "minnesota", "mississippi", "missouri", "montana", "nebraska", "nevada", "new hampshire", "new jersey", "new mexico", "new york", "north carolina", "north dakota", "ohio", "oklahoma", "oregon", "pennsylvania", "rhode island", "south carolina", "south dakota", "tennessee", "texas", "utah", "vermont", "virginia", "washington", "west virginia", "wisconsin", "wyoming"),                           class = "factor"                 ),          state = structure(1:50,                            .label = c("alabama", "alaska", "arizona", "arkansas", "california", "colorado", "connecticut", "delaware", "florida", "georgia", "hawaii", "idaho", "illinois", "indiana", "iowa", "kansas", "kentucky", "louisiana", "maine", "maryland", "massachusetts", "michigan", "minnesota", "mississippi", "missouri", "montana", "nebraska", "nevada", "new hampshire", "new jersey", "new mexico", "new york", "north carolina", "north dakota", "ohio", "oklahoma", "oregon", "pennsylvania", "rhode island", "south carolina", "south dakota", "tennessee", "texas", "utah", "vermont", "virginia", "washington", "west virginia", "wisconsin", "wyoming"),                            class = "factor"                  ),          stateabbreviation = structure(                                  c(2l, 1l, 4l, 3l, 5l, 6l, 7l, 8l, 9l, 10l, 11l, 13l, 14l, 15l, 12l, 16l, 17l, 18l, 21l, 20l, 19l, 22l, 23l, 25l, 24l, 26l, 29l, 33l, 30l, 31l, 32l, 34l, 27l, 28l, 35l, 36l, 37l, 38l, 39l, 40l, 41l, 42l, 43l, 44l, 46l, 45l, 47l, 49l, 48l, 50l),                                 .label = c("ak", "al", "ar", "az", "ca", "co", "ct", "de", "fl", "ga", "hi", "ia", "id", "il", "in", "ks", "ky", "la", "ma", "md", "me", "mi", "mn", "mo", "ms", "mt", "nc", "nd", "ne", "nh", "nj", "nm", "nv", "ny", "oh", "ok", "or", "pa", "ri", "sc", "sd", "tn", "tx", "ut", "va", "vt", "wa", "wi", "wv", "wy"),                                 class = "factor"                              ),          padd = structure(                     c(4l, 5l, 5l, 4l, 5l, 1l, 2l, 2l, 2l, 2l, 5l, 1l, 3l, 3l, 3l, 3l, 3l, 4l, 2l, 2l, 2l, 3l, 3l, 4l, 3l, 1l, 3l, 5l, 2l, 2l, 4l, 2l, 2l, 3l, 3l, 3l, 5l, 2l, 2l, 2l, 3l, 3l, 4l, 1l, 2l, 2l, 5l, 2l, 3l, 1l),                     .label = c("pad iv", "padd i", "padd ii", "padd iii", "padd v"),                     class = "factor"                 ),          subareainpadd = structure(                              c(1l, 1l, 1l, 1l, 1l, 1l, 2l, 3l, 4l, 4l, 1l, 1l, 1l, 1l, 1l, 1l, 1l, 1l, 2l, 3l, 2l, 1l, 1l, 1l, 1l, 1l, 1l, 1l, 2l, 3l, 1l, 3l, 4l, 1l, 1l, 1l, 1l, 3l, 2l, 4l, 1l, 1l, 1l, 1l, 2l, 4l, 1l, 4l, 1l, 1l),                              .label = c("", "sub a", "sub b", "sub c"),                              class = "factor"                          ),          subareainpaddname = structure(                                  c(1l, 1l, 1l, 1l, 1l, 1l, 4l, 2l, 3l, 3l, 1l, 1l, 1l, 1l, 1l, 1l, 1l, 1l, 4l, 2l, 4l, 1l, 1l, 1l, 1l, 1l, 1l, 1l, 4l, 2l, 1l, 2l, 3l, 1l, 1l, 1l, 1l, 2l, 4l, 3l, 1l, 1l, 1l, 1l, 4l, 3l, 1l, 3l, 1l, 1l),                                  .label = c("", "central atlantic", "lower atlantic", "new england"),                                  class = "factor"                              ),          paddname = structure(                         c(2l, 5l, 5l, 2l, 5l, 4l, 1l, 1l, 1l, 1l, 5l, 4l, 3l, 3l, 3l, 3l, 3l, 2l, 1l, 1l, 1l, 3l, 3l, 2l, 3l, 4l, 3l, 5l, 1l, 1l, 2l, 1l, 1l, 3l, 3l, 3l, 5l, 1l, 1l, 1l, 3l, 3l, 2l, 4l, 1l, 1l, 5l, 1l, 3l, 4l),                         .label = c("east coast", "gulf coast", "midwest", "rocky mountain", "west coast"),                         class  = "factor"                     )      ),       .names = c("state", "state", "stateabbreviation", "padd", "subareainpadd", "subareainpaddname", "paddname"),      class = "data.frame",      row.names = c(na, -50l) ) 

to build chart:

padd_names<-unique(padds$paddname)  map("state", interior = false) padd1<-subset(padds, padd=="padd i") padd2<-subset(padds, padd=="padd ii") padd3<-subset(padds, padd=="padd iii") padd4<-subset(padds, padd=="padd iv") padd5<-subset(padds, padd=="padd v")  map('state', region = padd1$state, fill=true, col="red", add=true, names=true)    # map of 4 states map('state', region = padd2$state, fill=true, col="green", add=true, names=true)    # map of 4 states map('state', region = padd3$state, fill=true, col="blue", add=true, names=true)    # map of 4 states map('state', region = padd4$state, fill=true, col="yellow", add=true, names=true)    # map of 4 states map('state', region = padd5$state, fill=true, col="purple", add=true, names=true)    # map of 4 states  map.text("state", regions=padds$state, labels=as.character(padds$stateabbreviation), add=true) #add labels 

this how color states , add labels:

library(maps) map("state", interior = false) map('state', region = c('illinois', 'indiana', 'iowa', 'ohio'), fill=true, col="red", add=true)    # map of 4 states map.text("state", regions=c("illinois", "indiana", "iowa", "ohio"), labels=as.character(c("il", "in", "ia", "oh")), add=true) #add labels 

Comments

Popular posts from this blog

cakephp - simple blog with croogo -

How to group boxplot outliers in gnuplot -

bash - Performing variable substitution in a string -