R 闪亮应用程序:无法使用ggplot2生成正确的绘图

R 闪亮应用程序:无法使用ggplot2生成正确的绘图,r,ggplot2,shiny,R,Ggplot2,Shiny,我的问题的解决方案必须是一条直线,但我正在使我的婴儿步有光泽。 请考虑的例子 我对其进行了修改,使其使用ggplot2生成绘图和散点图,而不是条形图。我将代码粘贴到下面。显然存在一个错误,因为ggplot2没有在y轴上绘制每列的值。有人能帮我吗?谢谢 library(tidyverse) library(shiny) # Rely on the 'WorldPhones' dataset in the datasets # package (which generally comes

我的问题的解决方案必须是一条直线,但我正在使我的婴儿步有光泽。 请考虑

的例子 我对其进行了修改,使其使用ggplot2生成绘图和散点图,而不是条形图。我将代码粘贴到下面。显然存在一个错误,因为ggplot2没有在y轴上绘制每列的值。有人能帮我吗?谢谢

 library(tidyverse)
 library(shiny)


 # Rely on the 'WorldPhones' dataset in the datasets
 # package (which generally comes preloaded).
 library(datasets)

 nn <- row.names(WorldPhones) %>% as.numeric

 ww <- WorldPhones %>%
    as_tibble %>%
    mutate(year=nn) %>%
    select(year, everything())

 mycolnames <- colnames(WorldPhones)

 # Use a fluid Bootstrap layout
 ui <- fluidPage(    

     # Give the page a title
     titlePanel("Telephones by region"),

     # Generate a row with a sidebar
     sidebarLayout(      

    # Define the sidebar with one input
     sidebarPanel(
     selectInput("region", "Region:", 
              choices=mycolnames),
      hr(),
      helpText("Data from AT&T (1961) The World's Telephones.")
     ),

     # Create a spot for the barplot
     mainPanel(
      plotOutput("phonePlot")  
    )

    )
    )


 # Define a server for the Shiny app
  server <- function(input, output) {

  # Fill in the spot we created for a plot
   output$phonePlot <- renderPlot({

  ## plot(ww[,input$region]*1000, 
   ##         main=input$region,
   ##         ylab="Number of Telephones",
   ##      xlab="Year")

  ggplot(ww, aes(x=year, y=input$region
                      )) +
  geom_point(size=3, shape=1, stroke=2)  
  })
   }

  shinyApp(ui = ui, server = server)

问题是您在这里传递的是长度为1的字符向量y=input$region。您可以这样做以实际传递列:

ggplot(ww, aes(x=year, y=ww[[input$region]])) +
  geom_point(size=3, shape=1, stroke=2)