How can I change the color of wedges in a rose diagram in ggplot?

231 views Asked by At

I have a rose diagram (code below) that I plotted in ggplot but I can't figure out how to change the color of the wedges. No matter what I try they remain black. This is the first time I have ever used ggplot so it may be something very simple.

Thanks!

rose <- ggplot(mapping = aes(x = Degrees))+
  stat_bin(breaks = (0:8 - 0.5)/8 * 360, color='white') +
  scale_x_continuous(
    breaks = 0:7/8*360,
    labels = c("N", "NE", "E", "SE", "S", "SW", "W", "NW")
  ) +
  coord_polar(start=-pi/8)
rose
1

There are 1 answers

1
chemdork123 On

You're looking for the fill aesthetic. color controls the color of lines and points. When considering shapes and polygons, color controls the outer line of the shape. The aesthetic fill controls the color inside the shape. Here's a clear example:

library(ggplot2)

set.seed(123)
df <- data.frame(degrees = sample(1:360, 1000, replace=TRUE))

ggplot(df, aes(x=degrees)) +
  stat_bin(breaks=(0:8 - 0.5)/8 * 360, color='red', fill='skyblue') +
  scale_x_continuous(
    breaks=0:7/8*360,
    labels=c('N','NE','E','SE','S','SW','W','NW')
  ) +
  coord_polar(start=-pi/8)

Note that the line outside is red and the shapes themselves are skyblue.

enter image description here