Reputation: 11
I have a dataset with three columns. Below is the header(data1, 5):
data1=data.frame(species=c("600162", "600006", "600264", "600077", "600265"), Bearing=c(158,47,223,318,71),Distance=c(4702,6642,3108,130000,16455))
I wish to create a graph with vectors direction based on degrees of "Bearing", and the length of the vector based on "Distance"
May I know what is the best course of action? Thank you very much in advance for your kind attention.
Upvotes: 1
Views: 234
Reputation: 66870
library(ggplot2)
# sin/cos swapped b/c Bearing is clockwise from top
ggplot(data1, aes(xend = Distance * sin(Bearing * pi / 180),
yend = Distance * cos(Bearing * pi / 180))) +
geom_segment(aes(x = 0, y = 0), arrow = arrow(length = unit(0.1, "inches"), type = "closed")) +
ggrepel::geom_text_repel(aes(x = Distance * sin(Bearing * pi / 180),
y = Distance * cos(Bearing * pi / 180),
label = species), size = 3) +
coord_equal()
Upvotes: 1