我有一个表示项目运行状况的数据,例如绿色,红色,黄色和无。
问题是颜色与文本不匹配。当数据集中存在绿色,红色,黄色时,它匹配。但是,在其他情况下,它们与文本不匹配,例如红色,它会变成黄色。
有什么方法可以解决这个问题吗?
我很感激帮助!
output$PieHealth <- renderPlotly({
Projects <- Projects[Projects$VP %in% c(input$checkbox),]
PieData2 <- Projects[,c(1,4)]
PieData2$ID <- 1
PD2 <- aggregate(cbind(PieData2$ID)~HealthName, data = PieData2, FUN=sum)
#PD2 <- PD2[-2,] #Delete 'None' Value
plot_ly(PD2, labels = ~PD2$HealthName, values = ~PD2$V1, type = 'pie',
textposition = 'inside',
textinfo = 'percent',
insidetextfont = list(color = '#FFFFFF'),
hoverinfo = 'text',
text = ~paste(PD2$HealthName),
marker = list(colors = c('#229954', '#ffc107','#d32f2f'),
line = list(color = '#FFFFFF', width = 1))) %>%
layout(title = "Project Health",
xaxis = list(showgrid = FALSE, zeroline = FALSE, showticklabels = FALSE),
yaxis = list(showgrid = FALSE, zeroline = FALSE, showticklabels = FALSE),
showlegend = FALSE)
})