Problem
I want to draw a number of arrows on a map. With some googling, I've learned that annotation_custom
with rasterGrob
can do the thing:
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()
However, when I run this script, I only got arrows but not background image:
Attachment
est_err_structured.csv
floorplan.png