使用ggplot在地图中连接2个点 [英] Connecting 2 points in a map using ggplot

查看:112
本文介绍了使用ggplot在地图中连接2个点的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

(ggmap)
library(ggplot2)

我有以下代码在ggmap中绘制2个点

  

d < - data.frame(lat = c(12.97131,12.98692),
lon = c(77.5121,77.68627))

班加罗尔< - get_map (印度班加罗尔,zoom = 12)

p < - ggmap(班加罗尔)
p + geom_point(data = d,aes(x = lon,y = lat) red,size = 3)

ggplot(p)

这些点在地图上显示为红点。如何连接这些点?

解决方案

不需要最终的 ggplot(p)(这可能会引发错误),我会使用 geom_path



<$ p $ (数据= d,aes(x = lon,y = lat),颜色=红色,尺寸= 3)
p + geom_path(data = d,aes(x = lon,y = lat),color =black,size = 1)
##或....
p + geom_line(data = d,aes(x = lon,y = lat),color =black,size = 1)


I have the following code to plot 2 points in ggmap

library(ggmap)
library(ggplot2)

d <- data.frame(lat=c(12.97131,12.98692),
        lon=c(77.5121,77.68627))

Bangalore <- get_map("Bangalore,India", zoom=12)

p <- ggmap(Bangalore)
p + geom_point(data=d, aes(x=lon, y=lat),color="red",size=3)

ggplot(p)

These points are showing as red dots in the map. How can I connect these points?

解决方案

No need for the final ggplot(p) (that's probably throwing an error on your end) and I'd use geom_path:

p <- ggmap(Bangalore)
p <- p + geom_point(data=d, aes(x=lon, y=lat),color="red",size=3)
p + geom_path(data=d, aes(x=lon, y=lat), color="black", size=1)
## or....
p + geom_line(data=d, aes(x=lon, y=lat), color="black", size=1)

这篇关于使用ggplot在地图中连接2个点的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆