我正在尝试创建一个圆环图并且难以添加颜色渐变。我希望能够采取所有不同的类别,并将它们从任何颜色淡入淡出。是否有捷径可寻?在R中添加颜色渐变到geom_rect
data<-data.frame(count=c(39,36,19,6), category=c("a","b","c","d"))
data$fraction = data$count/sum(data$count)
data = data[order(data$fraction), ]
data$ymax = cumsum(data$fraction)
data$ymin = c(0, head(data$ymax, n=-1))
#~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
#Create Plot
fill <- c("blue3","cyan3","darkgrey","forestgreen")
p1 = ggplot(data, aes(fill=category, ymax=ymax, ymin=ymin, xmax=4, xmin=3.5))
+ geom_rect(colour="White") +
coord_polar(theta="y") +
scale_fill_manual(values=fill)+
theme_bw()+
theme(panel.grid=element_blank())+
theme(axis.ticks=element_blank()) +
xlim(c(0, 4)) +
theme(axis.text=element_blank()) +
labs(title="donut plot")
print(p1)
这个前面的问题可能有帮助... http://stackoverflow.com/questions/20069660/r-gradient-fill-for-geom-rect-in -ggplot2 –
即将不同的颜色分配给不同的值以创建褪色的外观。我想要做的是让每个值的颜色具有渐变效果。所以对于类别“a”,我希望这件作品从“白色”渐变为“cyan3” –