添加点地区分布图中GGPLOT2(Add Points to Choropleth Map in g

2019-06-28 02:04发布

我期待在从哈德利韦翰的下面的例子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 "+""

如何添加这些点?

Answer 1:

这似乎只是正常工作对我来说:

base_map + 
    geom_point(aes(long, lat,fill = NULL,group = NULL), size = 1,data=us.cities) + 
    borders("state", size=.5)

虽然你可能希望排除在HI和AK的城市,像我一样,产生这一版的情节:



文章来源: Add Points to Choropleth Map in ggplot2
标签: r maps ggplot2