
Geom_bar(data = data, aes(x = dir.binned), width = 1, colour="black", size = 0.3, alpha=0.5) + # On top of everything we place the histogram bars. # We want 12 vertical lines representing the centers of the 30° ranges. Geom_hline(yintercept = 30000, colour = "black", size = 0.3) + # Now we add a darker horizontal line as the top border at 30000.
#Add frequency axis to rose diagram r series#
# since the plot background is blank we'll add a series of horizontal lines, at 5000 count intervals, up to 25000. The first parts of this plot will plot a rectangular histogram, only the coord_polar function wraps it into a wind rose. Our y-axis will have breaks every 5000 counts so we’ll use 30000 as the max for the y-axis. We need this value to set our y-scales correctly. So there are 28403 counts of the 240° bin. What we need to know before going on is the frequency of the most common bin. The main plot sets things up quite specifically. Theme( = element_text(size=8, face = "plain"),Ī = element_text(size=8, face = "plain"),Ī = element_text(size=8, face = "plain", hjust = 0.9, vjust = 1.3), This turns off the default background for ggplot2 so that we can define the borders and grids manually later. The important points here are blank values for panel.border and id.

# Assign bin names to the original data set

# assign each direction to a bin rangeĭir.labels <- as.character(c(seq(0, 360-deg, by = deg), 0)) Finally we’ll attach the new variable to the main dataset. We’ll also generate some pretty labels and assign them as levels of the new object. Now we generate a factor variable, exchanging the directions with the ranges. First we will define the bin width (30°), then we will define dir.breaks which stores the range of each bin as follows 345°-15°, 15°-45°, 45°-75° etc.

There are various ways to split and plot these data. That looks like a reasonable distribution of directions, favouring 225°.

Hist(data$direction, main = "Histogram of hypothetical direction frequencies.", xlab = "Direction", ylab = "Frequency") For this tutorial I will simulate 100000 directions using the wrapped normal function (rwrpnorm) from the CircStats package. The dataĪs I mentioned, my data was related to seal swimming directions, gathered from satellite tags. In fact, if you look through the ggplot2 call, it is basically a histogram until the last couple of lines, where it is wrapped into a wind rose. In reality it doesn’t matter too much what you want to plot, and these sorts of plots are more generally used for wind direction illustrations. In my article I wanted a graphic which illustrated the preferred outward post-moult migration direction of adult female southern elephant seals from Marion Island.
#Add frequency axis to rose diagram r how to#
As before, I relied heavily on Stack Exchange and many other sites for figuring out how to get my plot looking the way I needed it to, and so this is my attempt to contribute back to the broader community. This is another post regarding some plots that I needed to make for a publication.
