R- Shiny-如何更改饼图中的图例颜色?

时间:2018-12-24 06:33:56

标签: r shiny

我想更改饼图中的图例颜色。 这是代码:

library(ECharts2shiny)
library(shiny)

dat5 <- c(rep("Female", 3376), rep("Male", 2180))

ui <- shinyUI(
dashboardPage(dashboardHeader(title = "PSM"),
dashboardBody(
mainPanel(
tabsetPanel(
tabPanel(
loadEChartsLibrary(),  tags$div(id="test5", 
style="width:60%;height:300px;"),                                                                           
deliverChart(div_id = "test5"))

server <- shinyServer(function(input,output){  
renderPieChart(div_id = "test5", data = dat5 )    })

有人可以帮助我如何更改图例颜色吗?

1 个答案:

答案 0 :(得分:0)

希望有帮助:

library(shiny)
library(shinydashboard)

dat5 <- c(rep("Female", 3376), rep("Male", 2180))
app <- shinyApp(
ui <- shinyUI(
  dashboardPage(dashboardHeader(title = "PSM"),
                dashboardSidebar(),
                dashboardBody(
                  mainPanel(
                    tabsetPanel(
                      tabPanel(tags$div(id="test5", 
                                        style="width:60%;height:300px;"),                                                                           
                        plotOutput("pie_chart"))
                    ))))
                    ),

                      server <- shinyServer(function(input,output){  
                        output$pie_chart <- renderPlot({
                          df <- table(dat5)
                          cols <- rainbow(length(df))
                          pie(df, col = cols)

                        })
                          })
)

runApp(app)