根据答案https://stackoverflow.com/a/26748780/1172302和以下数据
"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"
馅饼可以通过
派生# 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()
如何将cd$Color
中定义的颜色用于外圈的片段,为内圈定义另外四种自定义颜色,最后避免使用cd$Category
中的类别(“Ec” “,”Go“,”So“和”Se“一起出现在传奇中?
答案 0 :(得分:0)
我无法回答你的所有问题,但是如果你扩展你的数据框以及一个描述内部颜色的附加列并重写如下的绘图代码,它应该可以工作
#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()