【发布时间】:2021-02-06 22:45:46
【问题描述】:
我需要创建一个selectInput 来选择一列来绘制geom_bar()。
我一直在尝试的:
用户界面
tabItems(
tabItem("Coop_ativas",
fluidPage(h1("Cooperativas Brasileiras")),
dataTableOutput("cooptable"),
box(plotOutput("correlation_plot"), widht = 8),
box(selectInput("features", "Características:",
c("situacao_cadastral", "identificador_matriz_filial")), width = 4),
box(plotOutput("regiao_plot"), widht = 8),
box(selectInput("regiao", "Região:",
choices = list("Estado" = "uf", "Região" = "regiao"),
selected = "Estado"))
))
服务器
output$regiao_plot <- renderPlot({
Coop_ativas %>% select(input$regiao[1]) %>% group_by(input$regiao[1]) %>% count() %>% arrange(desc(n)) %>% head(10) %>%
ggplot(aes(reorder(input$regiao[1], n), n), ) +
geom_bar(stat="identity", fill="steelblue") +
geom_text(aes(label=n), vjust=0.5, hjust=-0.5, color="darkgrey", size=3) +
labs(title = "Cooperativas Ativas por Estado",
subtitle = "02/2020",
caption = "Fonte: RFB, tratado por OBSCOOP/USP",
#tag = "Figure 1",
x = "Estado",
y = "Quantidade") +
theme_minimal() + theme(plot.title = element_text(hjust = 0.5),
plot.subtitle = element_text(hjust = 0.5),
plot.caption = element_text(0.0)) +
coord_flip()
})
input$regiao[1] 在哪里,我希望它是 uf 或 regiao。
【问题讨论】: