如何使用ggplot2在世界地图上绘制单点? [英] How do I plot a single point on a world map, using ggplot2?
本文介绍了如何使用ggplot2在世界地图上绘制单点?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
all_states < - map_data(usa)
p < - p + geom_polygon(data = all_states,aes (x = long,y = lat,group = group,legend = FALSE))
p
还有,是否有可能从网格中删除网格和纬度长整型值?
解决方案
<$ c $ b $ 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单点
p <-p + geom_point(data = sf,aes(long,lat),color =green,size = 4)
p
注意 :由于版本0.9.2 opts
已被取代通过主题
。例如, opts(panel.background = theme_blank())
会变成 theme(panel.background = element_blank())
。
on a world map, how do I plot a single point?
all_states <- map_data("usa")
p <- p + geom_polygon( data=all_states, aes(x=long, y=lat, group = group, legend = FALSE))
p
Also, is it possible to remove the grid and the lat long values form the map?
解决方案
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
Note: Since version 0.9.2 opts
has been replaced by theme
. So for example, opts(panel.background = theme_blank())
would become theme(panel.background = element_blank())
.
这篇关于如何使用ggplot2在世界地图上绘制单点?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文