简体   繁体   中英

Bar plot with polar coordinates, adjust for tapering in ggplot

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.

在此处输入图片说明

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?

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())

情节

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.

情节

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM