我在开发一个能创建react 图表的应用程序. 对于其中之一-圆环图-我无法使图例 colored颜色 与文本标签 colored颜色 匹配. 在另一个图表上刷动时会创建一个react 性的框架.这个df然后被用来创建圆环图. 例如,画笔动作的框架看起来像这样
dng<-structure(list(Outcome = structure(3:1, levels = c("Home", "Draw",
"Away"), class = "factor"), Counts = 4:2, `%` = c(44.44, 33.33,
22.22), fraction = c(0.44, 0.33, 0.22), ymax = c(0.44, 0.77,
0.99), ymin = c(0, 0.44, 0.77), labelPosition = c(0.22, 0.605,
0.88), label = c("Away:\n 44.44%", "Draw:\n 33.33%", "Home:\n 22.22%"
)), row.names = c(NA, -3L), class = "data.frame")
以下是我为我的甜甜圈图表编写的代码
output$plotui3 <- renderPlot({
dng<-cutoffs()
dng$fraction<- round(dng$Counts/sum(dng$Counts),2)
dng$ymax<- cumsum(dng$fraction)
dng$ymin<- c(0,head(dng$ymax, n=-1))
dng$labelPosition <- (dng$ymax + dng$ymin) / 2
dng$label <- ifelse(dng$Counts==0, "", paste0(dng$Outcome, ":\n ", dng$'%',"%"))
g3<-ggplot(dng, aes(ymin=ymin,ymax=ymax,xmax=4,xmin=3,fill=Outcome)) +
geom_rect()+
geom_text( x=2, aes(y=labelPosition, label=label,color=Outcome), size=6,show.legend = F)+
coord_polar(theta="y") +
xlim(c(0, 4)) +
theme_ipsum() +
theme_void()+
scale_fill_fivethirtyeight(labels = c("Win", "Draw","Lose"),breaks = c("Home","Draw","Away"))+
theme(legend.position="bottom",legend.text=element_text(size=20),legend.title = element_text(size=20))
g3
})
但是,标签的 colored颜色 始终处于关闭状态
我想让标签与图例的 colored颜色 相匹配,以便
clrs = c(Home = "#008FD5", Draw = "#FF2700", Away = "#77AB43")
谢谢你的帮助