Reputation: 1780
I would like to create of the PADD areas of the US in R with the bottom part of Canada. Is this possible?
I would like to keep the labels, and have the states highlighted based on the PADD. I tried looking for an example online like this but couldn't find it.
library(maps)
map("state", interior = FALSE)
map("state", boundary = FALSE, col="gray", add = TRUE)
This is missing the state labels, colour and the bottom part of Canada.
Thanks, I'm am able to get the shading to sort of work but after I fill in one PADD the next fills in the past PADDS. Also, I would still like to add the bottom part Canada to the mix. Lastly I'm currently getting an error when adding the text lables.
For a table of the PADDS and 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 the 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 four states
map('state', region = PADD2$State, fill=TRUE, col="green", add=TRUE, names=TRUE) # map of four states
map('state', region = PADD3$State, fill=TRUE, col="blue", add=TRUE, names=TRUE) # map of four states
map('state', region = PADD4$State, fill=TRUE, col="yellow", add=TRUE, names=TRUE) # map of four states
map('state', region = PADD5$State, fill=TRUE, col="purple", add=TRUE, names=TRUE) # map of four states
map.text("state", regions=PADDS$State, labels=as.character(PADDS$StateAbbreviation), add=TRUE) #add labels
Upvotes: 2
Views: 1161
Reputation: 6516
This is how you color states and add labels:
library(maps)
map("state", interior = FALSE)
map('state', region = c('illinois', 'indiana', 'iowa', 'ohio'), fill=TRUE, col="red", add=TRUE) # map of four states
map.text("state", regions=c("illinois", "indiana", "iowa", "ohio"), labels=as.character(c("IL", "IN", "IA", "OH")), add=TRUE) #add labels
Upvotes: 3