【发布时间】:2016-08-10 16:00:18
【问题描述】:
问题
我想在地图上画一些箭头。通过谷歌搜索,我了解到 annotation_custom 和 rasterGrob 可以做到这一点:
library(ggplot2)
library(png)
library(grid)
img = readPNG('floorplan.png')
g = rasterGrob(img, interpolate = TRUE)
data = read.csv('est_err_structured.csv', header = FALSE)
x1 = data$V1
y1 = data$V2
x2 = data$V3
y2 = data$V4
p = ggplot() +
geom_segment(data = data, mapping = aes(x = x1, y = y1, xend = x2, yend = y2),
arrow = arrow(length = unit(0.2, 'cm'))) +
annotation_custom(g, xmin = -Inf, xmax = Inf, ymin = -Inf, ymax = Inf) +
xlab('x (m)') +
ylab('y (m)') +
theme_bw()
pdf('err_on_map.pdf')
p
dev.off()
但是,当我运行这个脚本时,我只有箭头,但没有背景图片:
附件
est_err_structured.csv-
floorplan.png
参考文献
【问题讨论】:
-
只是好奇,这是你的猫的 GPS 追踪器数据吗?