Mar*_*ras 5 plot r map ggplot2 ggmap
我想geom_segment在我的ggmap对象上绘制线条(准确地说:元素)(ggplot2据我所知,这是一个对象).
我使用以下代码:
library(ggmap)
mapImageData <- get_map(location = c(lon = (16.8 + ( 17.2-16.8)/2),
lat = (51 + (51.2-51)/2)),
color = "color",
source = "google",
maptype = "roadmap",
zoom = 11)
ggmap(mapImageData, extent = "device", ylab = "Latitude", xlab = "Longitude") +
geom_segment(aes(x = 51, y = 16.8, xend = 51.2, yend = 17.2))
Run Code Online (Sandbox Code Playgroud)
正在绘制一张清晰的地图:

但没有出现(从geom_segment)线.我究竟做错了什么?
纬度值对应于y值,经度对应x值.所以你必须改变x和y值geom_segment().
ggmap(mapImageData, extent = "device", ylab = "Latitude", xlab = "Longitude") +
geom_segment(aes(y = 51, x = 16.8, yend = 51.2, xend = 17.2))
Run Code Online (Sandbox Code Playgroud)