首页 > 解决方案 > 从 radioButton 中选择的选项中获取 ggplot 的标题

问题描述

我正在尝试从用户选择的单选按钮中的选定选项中获取ggplot图的标题。我真的很感激任何帮助。

以下是带有伪造数据的相关代码:

侧边栏

sidebar <- dashboardSidebar(sidebarMenu(
  menuItem("Dashboard", tabName = "Data", icon = icon("dashboard")),
  radioButtons(inputId = "Partner", label = "Choose Partnership:", selected = "A",
             choices = c("A", "B", "C", "D"))),

身体

body <- dashboardBody( 
   fluidRow(
    tabBox(title = "Company",
    tabPanel("Partner", plotOutput("partner"))))
)

服务器

output$partner <- renderPlot({
        all_part  %>% 
        filter(partner == input$Partner) %>%
        ggplot(aes(x=level, fill = level)) +
        geom_bar() +
        ylab("Number of Participants") +
        theme_tufte() +
        ggtitle(" ") +   # How can I get this from the radiobutton choice ?#
        theme(plot.title = element_text(colour="black", size=14, face="bold"), 
              axis.title.x = element_text(color="black", size=10, face="bold"),
              axis.title.y = element_text(color="black", size=10, face="bold")) +
        theme(plot.subtitle = element_text(color="#0066CC", size=12, face="bold")) +
        theme(legend.title = element_text(colour="black", size=10, face="bold")) +
        theme(legend.position = "none") +
        theme(plot.background = element_rect(fill = "#CCFFFF"))  
})

标签: rggplot2shinyradio-buttonshinydashboard

解决方案


推荐阅读