R 如何更改一列以绘制几何图形条()?
我需要创建一个R 如何更改一列以绘制几何图形条()?,r,ggplot2,shiny,R,Ggplot2,Shiny,我需要创建一个selectInput来选择一列来绘制geom\u bar() 我一直在尝试: 用户界面 服务器 output$regiao_plot <- renderPlot({ Coop_ativas %>% select(input$regiao[1]) %>% group_by(input$regiao[1]) %>% count() %>% arrange(desc(n)) %>% head(10) %>%
selectInput
来选择一列来绘制geom\u bar()
我一直在尝试:
用户界面
服务器
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()
})
output$regiao\u plot%select(input$regiao[1])%%>%groupby(input$regiao[1])%%>%count()%%>%arrange(desc(n))%%>%head(10)%%
ggplot(aes(重新排序(输入$regiao[1],n),n),)+
几何图形栏(stat=“identity”,fill=“steelblue”)+
几何图形文本(aes(label=n),vjust=0.5,hjust=-0.5,color=“darkgrey”,size=3)+
实验室(title=“cooperativias Ativas por Estado”,
subtitle=“02/2020”,
caption=“Fonte:RFB,tratado por OBSCOOP/USP”,
#tag=“图1”,
x=“Estado”,
y=“量化数据”)+
theme_minimal()+主题(plot.title=element_text(hjust=0.5),
plot.subtitle=元素\文本(hjust=0.5),
plot.caption=element_text(0.0))+
coord_flip()
})
哪里是input$regiao[1]
我希望它是uf
或regiao
好的,刚刚找到它
只需将input$regiao
转换为sym
。
并与一起使用代码>
output$regiao_plot <- renderPlot({
col <- sym(input$regiao)
Coop_ativas %>% select(!! col) %>% group_by(!! col) %>% count() %>% arrange(desc(n)) %>% head(10) %>%
ggplot(aes(reorder(!! col, n), n), )
output$regiao\u plot%group\u by(!!col)%%>%count()%%>%arrange(desc(n))%%>%head(10)%%
ggplot(aes(重新排序(!!列,n),n),)
output$regiao_plot <- renderPlot({
col <- sym(input$regiao)
Coop_ativas %>% select(!! col) %>% group_by(!! col) %>% count() %>% arrange(desc(n)) %>% head(10) %>%
ggplot(aes(reorder(!! col, n), n), )