R:饼图在一些彩色切片上的阴影线

时间:2016-07-28 17:27:50

标签: r pie-chart

正如标题所述,我想制作一个饼图,其中一些切片同时具有:颜色和彩色阴影线(hachures)。我设法给正确的切片添加阴影线:

# At first create data
ges <- 94969
alle <- c(6379/ges,22264/ges,11018/ges,2079/ges,444/ges,7268/ges,2204/ges,322/ges,100/ges,9236/ges,1872/ges,5934/ges,4428/ges,14689/ges,3631/ges,1243/ges,1858/ges)
pct <- round(alle/sum(alle)*100, digits=2)
pct1 <- pct; pct1[pct1 < 0.3] <- NA
pct2 <- pct; pct2[pct2 >= 0.3] <- NA
pctgr <- c(round((6379+22264+11018+2079+444+7268+2204+322+100)/ges*100, 2), round((9236+1872+5934+4428+14689)/ges*100, 2), round((3631+1243+1858)/ges*100, 2))
lbls <- c(NA,NA,NA,NA, paste0("Gras- und\n Staudenfluren\n", pctgr[1], " %"),NA,NA,NA,NA,NA,NA,
          paste0("Wälder und Forste\n", pctgr[2], " %"),NA,NA,NA,
          paste0("Sonstige\n", pctgr[3], " %"))

# Then find out the angles of the slices (in radiant) for labelling:
library(plotrix)
pie(alle, density = c(NA,NA,NA,8,NA,8,8,NA,8,NA,NA,8,NA,NA,NA,NA,NA), labels = "",
    col=c("gold","gold3","goldenrod","red","gold4","red","red","darkorange","red","chartreuse4","forestgreen","red","green3","green4","tomato1","tomato2","tomato3"))
winkel <- floating.pie(0, 0, radius = 0.5, alle, plot = FALSE,
                       col=c("gold","gold3","goldenrod","red","gold4","red","red","darkorange","red","chartreuse4","forestgreen","red","green3","green4","tomato1","tomato2","tomato3"))

# Finally plot the pie and label it:
windows(width = 10, height = 8)
pie(alle, density = c(NA,NA,NA,8,NA,8,8,NA,8,NA,NA,8,NA,NA,NA,NA,NA), labels = "",
    col=c("gold","gold3","goldenrod","red","gold4","red","red","darkorange","red","chartreuse4","forestgreen","red","green3","green4","tomato1","tomato2","tomato3"))
pie.labels(0, 0, angles = winkel, labels = lbls, radius = 1.04)
pie.labels(0, 0, angles = winkel, labels = pct1, radius = 0.68, cex = 0.75, font =2)
pie.labels(0, 0, angles = winkel, labels = pct2, radius = 0.58, cex = 0.75, font = 2)

我必须两次绘制饼图,因为plotrix::floating.pie没有plot = FALSE参数,但我需要plotrix::floating.pie的角度来标记plotrix::pie.labels,我不知道其他双重标记的可能性,但我不仅可以使用plotrix::floating.pie,因为它不接受用于着色的矢量(对于应用于所有饼的着色密度只有一个数字)。
如您所见,阴影切片没有填充颜色。我怎么能改变它?

0 个答案:

没有答案
相关问题