我的ggplot有以下图例:
我想对各个图例变量进行分组,并添加组名和“括号”,如下图图例所示:
我的数据有两列:
1-美国各州
2-活动水平,范围为10(高)-1(低)
我也在使用数据-
美国<-map\U数据(“状态”),包含在ggplot/map包中。
我的代码:
ggplot()+ geom_map(data=us, map=us,aes(x=long, y=lat, map_id=region),
fill="#ffffff", color="#ffffff", size=0.15) +
geom_map(data=dfm4,map=us,aes(fill=ACTIVITY.LEVEL,map_id=STATENAME)
,color="#ffffff", size=0.15)+
scale_fill_manual("Activity",
values=c("10"="red4","9"="red2","8"="darkorange3",
"7"="orange3","6"="orange1",
"5"="gold2","4"="yellow","3"="olivedrab3","2"="olivedrab2",
"1"="olivedrab1"),
breaks=c("10","9","8","7","6","5","4","3","2","1"),
labels=c("High - 3","High - 2","High - 1","Moderate - 2","Moderate -
1","Minimal - 2","Minimal - 1","Low - 3","Low - 2","Low - 1"))+
labs(x="Longitude",y="Latitude")
可复制数据:
state<-c("alabama",
"alaska", "arizona", "arkansas", "california", "colorado", "connecticut",
"delaware", "district of columbia", "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",
"new york city", "north carolina", "north dakota", "ohio", "oklahoma",
"oregon", "pennsylvania", "puerto rico", "rhode island", "south carolina",
"south dakota", "tennessee", "texas", "utah", "vermont", "virgin islands",
"virginia", "washington", "west virginia", "wisconsin", "wyoming")
activity<-c("10", "10", "10", "10",
"8", "8", "6", "10", "10", "1", "10", "6", "4", "10", "10", "7",
"10", "10", "10", "2", "10", "10", "9", "9", "10", "10", "2",
"10", "8", "10", "10", "10", "10", "10", "3", "8", "10", "8",
"10", "10", "10", "10", "10", "10", "7", "10", "10", "1", "10",
"7", "10", "10", "9", "5")
reproducible_data<-data.frame(state,activity)