Диаграмма рассеяния ShinyApp отображает только одну точку - PullRequest
0 голосов
/ 08 марта 2019

Я пытаюсь создать приложение Shiny для создания диаграммы рассеяния на основе набора данных Iris.Код генерирует приложение, но отображает только одну точку на графике, независимо от того, какие настройки я выберу в приложении.Вот код:

options(warn = -1)
library(shiny)
library(shinythemes)
library(dplyr)
library(readr)
library(ggplot2)
options(warn=0)



# Define UI
ui <- fluidPage(theme = shinytheme("superhero"),
                titlePanel("Iris"),
  sidebarLayout(
    sidebarPanel(

      # Select Inputs
      selectInput(inputId = "y",
                  label = "Y-axis:",
                  choices = c("Sepal.Length", "Sepal.Width", "Petal.Length", "Petal.Width"),
                  selected = "Sepal.Length"),

      selectInput(inputId = "x",
                  label = "X-axis:",
                  choices = c("Sepal.Length", "Sepal.Width", "Petal.Length", "Petal.Width"),
                  selected = "Petal.Length")
      ),

    # Output
    mainPanel(
      plotOutput(outputId = "scatterplot")
    )
  )
)

# Define server function
server <- function(input, output) {

  # Create the scatterplot object the plotOutput function is expecting
  output$scatterplot <- renderPlot({
    ggplot(data = iris, aes(x = input$x, y = input$y))+
      geom_point(aes(color=Species, shape=Species))+
      geom_smooth(method="lm")
  })
}

shinyApp(ui=ui, server=server)

1 Ответ

0 голосов
/ 08 марта 2019

потому что ваш ввод $ x на самом деле является строкой.Поэтому замените aes() на aes_string() в вашем ggplot вызове:

library(ggplot2)

# This doesn't work: aes
ggplot(data = iris, aes(x = "Sepal.Length", y = "Sepal.Width"))+
  geom_point(aes(color=Species, shape=Species))+
  geom_smooth(method="lm")

# This works : aes_string
ggplot(data = iris, aes_string(x = "Sepal.Length", y = "Sepal.Width"))+
  geom_point(aes(color=Species, shape=Species))+
  geom_smooth(method="lm")

См .: передача строки в функцию ggplot

Добро пожаловать на сайт PullRequest, где вы можете задавать вопросы и получать ответы от других членов сообщества.
...