Proportional Arrows in ggplot

Based on the ggplot2 example of seals , I am trying to change the thickness of the arrows so that their overall size better reflects the data variable. I can specify the length and thickness, but I do not know how to change the size of the arrow. 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))
+4
source share
1 answer

I can’t say that this is a complete solution to your problem, but at least it could be the beginning.

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.7, "cm"))) + 
  scale_size(range = c(1, 2))

My changes are minimal: large arrowheads and scale. The upper limit of the size scale is most important if you want to avoid over-compaction.

enter image description here

, , , , . :

 ggplot(d, aes(x = long, y = lat, size = size)) +
   geom_segment(aes(xend = long + delta_long/100, yend = lat + delta_lat/100), 
               arrow = arrow(length = unit(0.7,"cm"))) + 
   scale_size(range = c(1, 2))

enter image description here

, ! . , . , .

UPD:, unit() , !

ggplot(d, aes(x = long, y = lat, size = size)) +
  geom_segment(aes(xend = long + delta_long/100, yend = lat + delta_lat/100), 
              arrow = arrow(length = unit(d$size * 5,"cm"))) + 
  scale_size(range = c(1, 2))

enter image description here

+4

All Articles