0

I want to use R to make a two-dimensional vector map. In other words, I have four inputs per data point: cartesian X and Y location, x and y vector length from that location. The output will be a rectangle with a bunch of arrows in it at different locations.

I just need a hint to get started, not a heavy answer. (I see a lot of great stuff on a Cheat Sheet, but nothing that really suggests what I need.)

Example source data:

enter image description here

Desired output:

enter image description here

Knom
  • 310
  • 4
  • 11
  • It's easier to help you if you include a simple [reproducible example](https://stackoverflow.com/questions/5963269/how-to-make-a-great-r-reproducible-example) with sample input and desired output that can be used to test and verify possible solutions. – MrFlick May 11 '21 at 21:57

1 Answers1

1

Here's an example with ggplot2. Next time please provide your data in a useable format.

## sample data
set.seed(47)
n = 5
df = data.frame(
  x = runif(n),
  y = runif(n),
  vx = rnorm(n),
  vy = rnorm(n)
)

df
#           x         y          vx          vy
# 1 0.9769620 0.6914124 -1.08573747 -0.92245624
# 2 0.3739160 0.3890619 -0.98548216  0.03960243
# 3 0.7615020 0.4689460  0.01513086  0.49382018
# 4 0.8224916 0.5433097 -0.25204590 -1.82822917
# 5 0.5735444 0.9248920 -1.46575030  0.09147291

library(ggplot2)
ggplot(df, aes(x = x, y = y)) +
  geom_segment(
    aes(xend = x + vx, yend = y + vy),
    arrow = arrow(length = unit(0.5, "cm"))
  )

enter image description here

Gregor Thomas
  • 136,190
  • 20
  • 167
  • 294