I'm looking at the following example from Hadley Wickham's 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")
I would then like to add points for some notable US cities to the map, but I haven't been able to. I've tried:
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)
But I get the following error:
Error in p + o : non-numeric argument to binary operator
In addition: Warning message:
Incompatible methods ("+.ggplot", "Ops.data.frame") for "+""
How can I add these points?
This seems to work just fine for me:
base_map +
geom_point(aes(long, lat,fill = NULL,group = NULL), size = 1,data=us.cities) +
borders("state", size=.5)
Although you may want to exclude the cities in HI and AK, as I did to produce this version of the plot:
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With