我想在加拿大的底部创建美国的PADD区域。这可能吗?
我想保留标签,并根据PADD突出显示状态。我试着像这样在网上寻找一个例子但却无法找到它。
library(maps)
map("state", interior = FALSE)
map("state", boundary = FALSE, col="gray", add = TRUE)
缺少州标签,颜色和加拿大的底部。
谢谢,我能够让阴影得到一些工作但是在我填写一个PADD之后,下一个填充过去的PADDS。此外,我仍然希望将加拿大的底部添加到混合中。最后,我在添加文本标签时出现错误。
PADDS和州的表格:
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)
)
构建图表:
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
答案 0 :(得分:2)
这是您对颜色状态和添加标签的方式:
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