4

I have created the following plot which gives the shape of the plot I desire. But when I facet wrap it, the shapes no longer remain triangular and become almost cellular. How can I keep the triangular shape after faceting?

Sample data:

lvls <- c("a","b","c","d","e","1","2","3","4","5","6","7","8","9","10","11","12","13","14","15")
df <- data.frame(Product = factor(rep(lvls, 3)), 
             variable = c(rep("Ingredients", 20),
                          rep("Defence", 20),
                          rep("Benefit", 20)),
             value = rnorm(60, mean = 5))

Now when I use this code, I get the shapes I desire.

ggplot(df,
   aes(x = variable,
       y = value,
       color = Product,
       group = Product)) +
geom_polygon(fill = NA) + 
coord_polar() 

enter image description here

However, the products are all on top of one another so ideally I would like to facet wrap.

ggplot(df,
   aes(x = variable,
       y = value,
       color = Product,
       group = Product)) +
geom_polygon(fill = NA) + 
coord_polar() +
facet_wrap(~Product)

enter image description here

But when I facet wrap, the shapes become oddly cellular and not triangular (straight lines from point to point). Any ideas on how to alter this output?

Thanks.

joran
  • 169,992
  • 32
  • 429
  • 468
Seanosapien
  • 432
  • 1
  • 5
  • 17
  • 1
    The 'cellular' shape you see is caused by the lines following the 'polar arc', instead of straight lines. [That's a common problem for polar charts](https://stackoverflow.com/questions/42562128/ggplot2-connecting-points-in-polar-coordinates-with-a-straight-line-2#42572133), and `geom_polygon` is the only exception to that rule. Evidently faceting reverts back to the standard use of lines in `coord_polar`. Follow the excellent answer linked above. – GGamba Jun 21 '17 at 12:39
  • Thank you. I am trying this but it seems I need to install dependencies for ggigraph as I am getting a whole host of non-zero entry messages. The dependencies = T argument does not resolve the issue either. – Seanosapien Jun 22 '17 at 08:25
  • 1
    You can just define your own `coord_radar`, without installing anything. put `coord_radar <- function (theta = "x", start = 0, direction = 1) { theta <- match.arg(theta, c("x", "y")) r <- if (theta == "x") "y" else "x" ggproto("CordRadar", CoordPolar, theta = theta, r = r, start = start, direction = sign(direction), is_linear = function(coord) TRUE)}` just before your graph – GGamba Jun 22 '17 at 08:28

0 Answers0