'Geom_spoke not plotting properly
I am trying to plot the length and angle of a bursting event for a marine animal. However, I dont think it is plotting properly. The event occurring at 75m has an ascent of 31 however this is not translating to the graph.
Further, I was wanting to cut the x-axis between 75 & 95.
ggplot(depth, aes(y=hour, x= Startdepth,)) +
geom_point(size = 3) +
geom_spoke(aes(angle = Pitchavg, radius = ascent), size = 1) +
theme_classic() +
scale_color_manual(values = c("#E7B800","#FC4E07", "#00AFBB", '#004E54')) +
annotate("rect", ymin = 5, ymax = 8.5, xmin = -1, xmax = 100,
alpha = .1, fill = "blue") +
annotate("rect", ymin = 16.5, ymax = 21.5, xmin = -1, xmax =100,
alpha = .1, fill = "blue") +
ylim(0, 24)
Below is a sample of my data:
Shark Startdepth Pitchavg ascent Hour
3 5.84887 15.170846 3.34844 19
4 0.424778 -1.737293333 0.014004 22
5 4.1233 7.2578775 0.02645 19
5 4.95108 17.91744 1.07518 19
5 4.77525 23.388734 0.95225 20
6 5.57968 -20.51986667 0 22
6 10.3285 37.778 4.48275 0
6 6.73732 17.5535036 5.52834 1
6 7.01584 27.8316 2.28104 1
6 0.977145 -24.41713333 0 4
6 55.3021 31.6784 9.9084 15
7 8.04433 24.8095 0 10
7 18.712 45.95876667 0 10
7 17.3225 26.36621125 16.374918 10
7 14.0488 37.84178571 0 11
7 20.24 35.13114667 0 11
7 25.5022 9.78095025 2.4459 13
Solution 1:[1]
The problem seems to be that geom_spoke accepts angle in radians and you have angles in degrees. Convert radians to degrees in aes and the plot seems right.
I have commented out the scale_color_* since the variable mapping to color was removed from the data, as said in the OP's comment.
x <- 'Shark Startdepth Pitchavg ascent Hour
3 5.84887 15.170846 3.34844 19
4 0.424778 -1.737293333 0.014004 22
5 4.1233 7.2578775 0.02645 19
5 4.95108 17.91744 1.07518 19
5 4.77525 23.388734 0.95225 20
6 5.57968 -20.51986667 0 22
6 10.3285 37.778 4.48275 0
6 6.73732 17.5535036 5.52834 1
6 7.01584 27.8316 2.28104 1
6 0.977145 -24.41713333 0 4
6 55.3021 31.6784 9.9084 15
7 8.04433 24.8095 0 10
7 18.712 45.95876667 0 10
7 17.3225 26.36621125 16.374918 10
7 14.0488 37.84178571 0 11
7 20.24 35.13114667 0 11
7 25.5022 9.78095025 2.4459 13'
depth <- read.table(textConnection(x), header = TRUE)
library(ggplot2)
ggplot(depth, aes(x = Startdepth, y = Hour)) +
geom_point(size = 3) +
geom_spoke(aes(angle = Pitchavg * pi/180, radius = ascent), size = 1) +
#scale_color_manual(values = c("#E7B800","#FC4E07", "#00AFBB", '#004E54')) +
annotate("rect", ymin = c(5, 16.5), ymax = c(8.5, 21.5), xmin = c(-1, -1), xmax = c(100, 100),
alpha = 0.1, fill = "blue") +
ylim(0, 24) +
theme_classic()

Created on 2022-05-12 by the reprex package (v2.0.1)
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|---|
| Solution 1 | Rui Barradas |

