Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/r/77.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
R 如何更改一列以绘制几何图形条()?_R_Ggplot2_Shiny - Fatal编程技术网

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), )