Reputation: 1459
I'm trying to show the bearings that individuals travelled away from a site and the distance travelled within 1 day, as well as the numbers of individuals travelling at different bearings.
Presently, I can make those basic plots in ggplot2:
# distance & bearing
ggplot(data=df,
aes(bear, dist)) +
geom_point() +
scale_y_log10()
# no. individuals & bearing
ggplot(data=df.postDepDT,
aes(bear)) +
geom_histogram(bins = 36)
#my data looks like the following
bear <- c(-172, -175, -160, -155, -150, -10, 23, 87, 122, 179)
dist <- c(5, 101, 326, 47, 23, 55, 6, 7, 44, 162)
df <- data.frame(bear, dist)
I would like my final plot to have two panels. The first is a circle with points at different lengths (indicating distance) radiating away from the circle in the direction of the bearing. These points would be connected to the circle along the bearing. The second is a histogram around the circle, showing numbers of individuals moving away from a circle along each bearing.
In these figures 0o (or North) would be at the top at -180o/180o (South) would be at the bottom, with -90o and 90o (west and east) on the left and right, respectively.
UPDATE:
Adding coord_polar() to the figures helps make a circular figure, however, I'm still unable to get the 0o value (for North) at the top of the figure (start=0 puts the 0o value at the bottom). Also, I'm still looking for a solution to connect the points in the first plot to the centre point.
Upvotes: 4
Views: 953
Reputation: 29095
Are you looking for something like this?
ggplot(data=df,
aes(bear, dist)) +
geom_segment(aes(xend = bear, yend = 0.1)) +
geom_point() +
scale_x_continuous(limits = c(-180, 180),
breaks = seq(-180, 180, 90)) +
# scale_y_log10() +
coord_polar(start = pi) +
theme_bw()
Explanations:
geom_segment()
expects aesthetics for x
, y
, xend
, & yend
. The "pre-coord_polar
" version of a circular chart with lines radiating from the centre would have been a chart in Cartesian coordinates with lines that drop down vertically to intersect the x-axis, so we'd want each xend
value to be the same as the x
value, and each yend
value to be the smallest possible (which would be 0 for distance, but since you are interested in the log scale for the y-axis, I've added a small positive value):ggplot(data=df,
aes(bear, dist)) +
geom_segment(aes(xend = bear, yend = 0.1)) +
geom_point() +
scale_x_continuous(limits = c(-180, 180),
breaks = seq(-180, 180, 90)) +
# scale_y_log10() +
# coord_polar(start = pi) +
theme_bw()
coord_polar()
expects the following for its start
argument (emphasis added):offset of starting point from 12 o'clock in radians
Since your bearing's actual values are in the c(-175, 179)
range, I expect your scale to be c(-180, 180)
. The default start = 0
would thus place -180/180
at the 12 o'clock position. To place 0
at the 12 o'clock position, set start = pi
, which is 180 degrees in radians.
yend
can result in the same point appearing to be at different distances from the centre. (see illustration below for some yend
values) On a more theoretical level, I understand log scale to be appropriate when we are comparing a large range of quantities, which isn't really the case here.p <- ggplot(data=df,
aes(bear, dist)) +
geom_point() +
scale_x_continuous(limits = c(-180, 180),
breaks = seq(-180, 180, 90)) +
scale_y_log10() +
coord_polar(start = pi) +
theme_bw()
gridExtra::grid.arrange(
p + geom_segment(aes(xend = bear, yend = 1)) + ggtitle("yend = 1"),
p + geom_segment(aes(xend = bear, yend = 0.1)) + ggtitle("yend = 0.1"),
p + geom_segment(aes(xend = bear, yend = 0.01)) + ggtitle("yend = 0.01"),
p + geom_segment(aes(xend = bear, yend = 0.001)) + ggtitle("yend = 0.001"),
nrow = 2
)
Upvotes: 4