0

I want to create a scoring plot, like those you often see in role-playing games, with positive and negative scores, using ggplot.

To do this I use geom_col and coord_polar. The problem is that the bars are not rectangles but trapezoids, as expected since the whole plotting space coordinates system is deformed.

enter image description here

Is it possible to adjust for this in order to have proper uniform bars (and add some space at the center of the plot to avoid overlapping)?

Bonus request: instead of a circular grid, is it possible to have a polygonal one, based on the number of values on the x-axis?

Bakaburg
  • 3,165
  • 4
  • 32
  • 64
  • 2
    Please share sample of your data using `dput()` (not `str` or `head` or picture/screenshot) so others can help. See more here https://stackoverflow.com/questions/5963269/how-to-make-a-great-r-reproducible-example?rq=1 – Tung Sep 07 '18 at 08:56

1 Answers1

0

You can use line segments instead of bars. The thickness would then depend on the size you choose, rather than the coordinate system:

# sample dataset
set.seed(333)
n.dim = 9
df <- data.frame(
  x = paste("attribute", seq(1, n.dim), sep = "."),
  score = rnorm(n.dim)
)

ggplot(df,
       aes(x = x, y = score, 
           xend = x, yend = 0,
           col = score >= 0)) +
  geom_segment(size = 15) +                 # adjust size for different bar thickness
  scale_y_continuous(expand = c(0.1, 0)) +  # increase space at plot centre
  coord_polar() +
  theme_minimal() +
  theme(legend.position = "none",
        axis.title = element_blank(),
        axis.text.y = element_blank(),
        panel.grid.major.x = element_blank())

plot

I think a polygon grid (rather than a circular one) would be more harder to interpret, as distance from plot centre no longer has a one-to-one relationship with the y-axis values. (See illustration below) It's probably possible to hack something that resembles a polygon grid in ggplot, but I've yet to see any such implementation myself.

plot

Z.Lin
  • 28,055
  • 6
  • 54
  • 94