Dear Hadley,
I've got it working.
pattern_restaurants <- ppp(info_restaurants$lng, info_restaurants$lat,
marks = info_restaurants$kitchen_type, window = owin(x_bounds,
y_bounds))
pattern_atms <- ppp(info_atms$lng, info_atms$atm_lat, marks = info_atms
$name, window = owin(x_bounds, y_bounds))
lng_atm <- c()
lat_atm <- c()
crossdistances <- nncross(pattern, pattern_atms)
for(i in 1:length(restaurants)) {
lng_atm <- append(lng_atm, atm_info$atm_lng[crossdistances$which
[i]])
lat_atm <- append(lat_atm, atm_info$atm_lat[crossdistances$which
[i]])
}
positions <- data.frame(info$lng, info$lat, lng_atm, lat_atm)
# Setup base plot
myplot <- ggplot(data = info, aes(x = lng, y = lat))
# Add layer
myplot <- myplot + geom_segment(aes(x = lng, y = lat, xend = lng_atm,
yend = lat_atm, colour = '#FF0000', size=1), arrow=arrow(length=unit
(0.35,"cm"))) +
coord_cartesian(xlim=x_bounds, ylim=y_bounds)
# Control margins
myplot <- myplot + no_margins
This gives me:
http://img.skitch.com/20090325-xgmsy49xqysghfxaih7s7e3uam.png
I guess I've misinterpreted the 'xend' and 'yend' parameters of
geom_segment.
Thanks for the eye opener :)
Cheers,