我想給顏色的餅圖。我用scale_fill_manual(values = c("orange", "red","blue", "yellow", "green"))
。我想爲蘋果提供紅色,爲橙色提供橙色,爲葡萄提供藍色等。但我的餅圖看起來不同。如何設置餅圖的特定顏色?
d1 <- data.frame(
labels = c("orange","apple","grape","pineapple","muskmelon"),
value = c(1632,29,1491,1991,29)
)
d1$pos <- cumsum(d1$value) - 0.5*d1$value
p1 <-ggplot(d1, aes(x="", y = value, fill = labels))
p1 <- p1 + geom_bar(stat="identity", width=1)
p1 <- p1 + ggtitle("fruits")
p1 <- p1 + panel_border()
p1 <- p1 + coord_polar(theta = "y")
p1 <- p1 + xlab("")
p1 <- p1 + ylab("")
p1 <- p1 + geom_text(aes(x="", y=pos,label=labels), size=10)
p1 <- p1 + scale_fill_manual(values = c("orange", "red","blue", "yellow", "green"))
p1 <- p1 + theme(legend.position="none",
legend.title=element_blank(),
axis.line=element_blank(),axis.text.x=element_blank(),
axis.ticks=element_blank(),
plot.title = element_text(lineheight=3, face="bold", color="black", size=25))
非常感謝! – aayan