Proportionally sized arrows in ggplot

Viewed 3574

Building on ggplot2's seals example, I'm trying to change the thickness of arrows so their overall size better reflects the data variable. I can specify length and thickness, but don't know how to change the size of the arrow-head. Very grateful for any suggestions.

require(ggplot2)
require(grid)

d = seals[sample(1:nrow(seals), 100),]
d$size = sqrt(sqrt(d$delta_long^2 + d$delta_lat^2))

ggplot(d, aes(x = long, y = lat, size = size)) +
  geom_segment(aes(xend = long + delta_long, yend = lat + delta_lat), arrow = arrow(length = unit(0.1,"cm")))

enter image description here


Edit

Solution code:

ggplot(d, aes(x = long, y = lat, size = size)) +
  geom_segment(aes(xend = long + delta_long, yend = lat + delta_lat), 
               arrow = arrow(length = unit(d$size/3, "cm"), type='closed')) +
  scale_size(range = c(0, 2))
1 Answers
Related