1

Based on the answer https://stackoverflow.com/a/26748780/1172302 and the following data

"Category","Driver","Intensity","Intensity (Numeric)","Intensity (Fraction)","ymin","ymax","Color"
"Ec","Loss","High",2,0.0833333333,0,0.0833333333,"orange"
"Ec","Stress","High",2,0.0833333333,0.0833333333,0.1666666666,"orange"
"Ec","Expectations","High",2,0.0833333333,0.1666666666,0.2499999999,"orange"
"Go","Lack","Very high",3,0.125,0.2499999999,0.3749999999,"red"
"Go","Competition","Very high",3,0.125,0.3749999999,0.4999999999,"red"
"So","Disrespect","Low",1,0.0833333333,0.4999999999,0.5833333332,"yellow"
"So","Harassment","High",2,0.0833333333,0.5833333332,0.6666666665,"orange"
"So","Upheaval","Low",1,0.0833333333,0.6666666665,0.7499999998,"yellow"
"Se","Vulnerability","High",2,0.0833333333,0.7499999998,0.8333333331,"orange"
"Se","Police","Very high",3,0.0833333333,0.8333333331,0.9166666664,"red"
"Se","Presence","Low",1,0.0833333333,0.9166666664,0.9999999997,"yellow"

a pie can be derived via

# prepare data
cd <- read.csv("piedata.csv", header = TRUE, check.names = FALSE )[1:8]
cd[[2]] <- as.character(cd[[2]])
cd[[3]] <- factor(cd[[3]], levels(cd[[3]])[c(2, 1, 3)])

# load library
library(ggplot2)

# plot
ggplot(cd) +
      geom_rect( aes ( fill = cd[[2]],
                       ymax = ymax, ymin = ymin, xmax = 4, xmin = 2)) +
      geom_rect( aes ( fill = cd[[1]],
                       ymax = ymax, ymin = ymin, xmax = 2, xmin = 0)) +
      xlim( c(0, 4)) +
      theme(aspect.ratio = 1) +
      coord_polar(theta="y") + theme_void()

enter image description here

How can I use the colors defined in cd$Color for the segments of the outer circle, define another four custom colors for the inner circle and, finally, avoid having the categories from cd$Category ("Ec", "Go", "So" and "Se") be present in the legend alltogether?

Community
  • 1
  • 1
Nikos Alexandris
  • 708
  • 2
  • 22
  • 36
  • 1
    so many segments. there's got to be a better way to communicate this data. – hrbrmstr Jun 07 '16 at 15:40
  • @hrbrmstr Tell me about it... (have to do it for now, find something more elegant later) – Nikos Alexandris Jun 07 '16 at 16:18
  • Are you saying you want multiple categories of `Driver` in the legend to have the same fill color? For setting colors, you can always give a named vector to `values` in the appropriate scale function - see, e.g., [this answer](http://stackoverflow.com/a/19068747/2461552). For keeping `Category` out of the legend you could try a messy work-around of suppressing the fill legend and adding a "fake" color legend with an additional `geom_rect` call. You would then need to use `override.aes` to fix the legend. – aosmith Jun 07 '16 at 18:36
  • @aosmith The colors "yellow", "orange" and "red" correspond to `cd$Intensity`. This is what I need to show. For example "High" intensity "Driver"s, should be "orange". Thanks, I'll give it a go. – Nikos Alexandris Jun 07 '16 at 19:24

1 Answers1

0

I can't answer all of your questions, but if you extend your data frame with an additional column describing the inner color and rewrite the plot code as followed, it should work

#plot
ggplot(cd) + 
    geom_rect(aes (fill = cd[[2]],
        ymax = ymax, ymin = ymin, xmax = 4, xmin = 2), fill = cd$Color_in) +
    geom_rect( aes ( fill = cd[[1]],
        ymax = ymax, ymin = ymin, xmax = 2, xmin = 0), fill = cd$Color_out) +
xlim(c(0, 4)) +
theme(aspect.ratio = 1) +
coord_polar(theta="y")+theme_void()
bbu
  • 1
  • 1