如何使用ggplot2在世界地图上绘制单个点?

时间:2012-02-23 22:10:01

标签: r ggplot2

在世界地图上,我如何绘制单点?

all_states <- map_data("usa")
p <- p + geom_polygon( data=all_states, aes(x=long, y=lat, group = group, legend = FALSE))
p

此外,是否可以从地图中删除网格和lat long值?

1 个答案:

答案 0 :(得分:7)

library(maps)
library(ggplot2)
world<-map_data('world')
sf<-data.frame(long=-122.26,lat=37.47)
p <- ggplot(legend=FALSE) +
geom_polygon( data=world, aes(x=long, y=lat,group=group)) +
opts(panel.background = theme_blank()) +
opts(panel.grid.major = theme_blank()) +
opts(panel.grid.minor = theme_blank()) +
opts(axis.text.x = theme_blank(),axis.text.y = theme_blank()) +
opts(axis.ticks = theme_blank()) +
xlab("") + ylab("")
# add a single point

p <- p + geom_point(data=sf,aes(long,lat),colour="green",size=4)
p

注意:由于版本0.9.2 optsreplaced theme。例如,opts(panel.background = theme_blank())将成为theme(panel.background = element_blank())