Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/r/79.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 选择输入作为ggplot2的参数?_R_Ggplot2_Shiny - Fatal编程技术网

R 选择输入作为ggplot2的参数?

R 选择输入作为ggplot2的参数?,r,ggplot2,shiny,R,Ggplot2,Shiny,在这个简单的例子中: library(shiny) library(dplyr) library(ggplot2) df1 <- structure( list( V1 = structure(1:2, .Label = c("no", "yes"), class = "factor"), `Long Name 1` = c(27.74, 25.75), `Long Name 2` = c(30.36,

在这个简单的例子中:

library(shiny)
library(dplyr)
library(ggplot2)
df1 <-
  structure(
    list(
      V1 = structure(1:2, .Label = c("no", "yes"), class = "factor"),
      `Long Name 1` = c(27.74, 25.75), `Long Name 2` = c(30.36,
                                                         27.7)
    ), .Names = c("V1", "Long Name 1", "Long Name 2"), row.names = c(NA,-2L), class = "data.frame"
  )


server <- function(input, output) {
  output$plot <- renderPlot({
    vrble <- as.name(input$select)
    df1 %>% ggplot(aes(x = V1, y = vrble, fill = V1)) +
      geom_bar(stat = "identity") +
      guides(fill = FALSE) + theme_bw() +
      scale_fill_brewer(palette = "Set1") +
      scale_y_continuous(limits = c(0,30), breaks = round(seq(min(0), max(30), by = 5),1))


  })
}

ui <- fluidPage(sidebarLayout(sidebarPanel(
  width = 3,
  selectInput(
    "select", label = h3("Variable"),
    choices = names(df1)[2:3],
    selected = 1
  )
),
mainPanel(plotOutput("plot"))))

shinyApp(ui = ui, server = server)

如何修复它?

您可能需要aes\u字符串而不是aes-类似于aes\u字符串X=V1,y=vrble,fill=V1@aosmith谢谢这就成功了。与dplyr无关,我的大脑在写文章时处于半睡眠状态
Error in data.frame(x = structure(1:2, .Label = c("no", "yes"), class = "factor"),  : 
                      object 'Long Name 1' not found
                    Error in data.frame(x = structure(1:2, .Label = c("no", "yes"), class = "factor"),  : 
                                          object 'Long Name 2' not found