1

I created a rose diagram based on the example here, but I need the y axis to show each bin as a percentage of the total. The data I am actually using is a vector of the different orientations of a group of animals. My example code currently would be something like:

Degrees <- runif(100, 0, 360)
# 45 degree bins
rose <- ggplot(mapping = aes(x = Degrees)) +
  stat_bin(breaks = (0:8 - 0.5)/8 * 360, color = "black", fill = "light grey") +
  scale_x_continuous(
    breaks = 0:7/8*360) +
  coord_polar(start=-pi/8)
rose

example rose plot generated

Thank you for any help you can give!

Trenton McKinney
  • 56,955
  • 33
  • 144
  • 158

2 Answers2

0

You could simply add:

rose + scale_y_continuous(labels = scales::percent)

enter image description here

Onyambu
  • 67,392
  • 3
  • 24
  • 53
  • I think I need to be more clear - I'll give a clearer example for the Degrees vector `Degrees <- c(10, 42, 60, 90, 92, 137, 182, 188, 220, 265, 268, 310, 320, 305)` so there are three values that fall within 292.5 and 337.5, so rather than this showing up as, say, a count of 3, or 300%, I need it to show up as 21.42857% – Liam Dickson May 12 '21 at 17:11
0

I think I've figured this out: I've added a y aesthetic into stat_bin that seems to have fixed the issue.

# 45 degree bins
rose <- ggplot(mapping = aes(x = Degrees)) +
  stat_bin(aes(y = (..count..)/sum(..count..)), breaks = (0:8 - 0.5)/8 * 360, color = "black", fill = "light grey") +
  scale_x_continuous(
    breaks = 0:7/8*360) +
  coord_polar(start=-pi/8)
rose

Displays y as count/sum(count)