我正在查看Hadley Wickham ggplot2
的以下示例:
library(ggplot2)
library(maps)
states<-map_data("state")
arrests<-USArrests
names(arrests)<-tolower(names(arrests))
arrests$region<-tolower(rownames(USArrests))
chloro<-merge(states, arrests, by="region")
chloro<-chloro[order(chloro$order), ]
qplot(long, lat, data=chloro, group=group, fill = assault, geom="polygon")
我想在地图上为一些着名的美国城市添加积分,但我无法做到。我试过了:
base_map<-qplot(long, lat, data=chloro, group=group, fill = assault, geom="polygon")
base_map + qplot(long, lat, data=us.cities) + borders("state", size=.5)
但是我收到以下错误:
Error in p + o : non-numeric argument to binary operator
In addition: Warning message:
Incompatible methods ("+.ggplot", "Ops.data.frame") for "+""
如何添加这些积分?
答案 0 :(得分:6)
这对我来说似乎很合适:
base_map +
geom_point(aes(long, lat,fill = NULL,group = NULL), size = 1,data=us.cities) +
borders("state", size=.5)
虽然您可能想要排除HI和AK中的城市,但正如我制作此版本的情节一样: