首页 > 解决方案 > 将 ggplot2 与 Rshiny 一起使用:ggplot y 轴上显示的级别不正确

问题描述

当我像这样在 RShiny 中使用 ggplot2 时:

# Define UI for miles per gallon application
shinyUI(pageWithSidebar(

  # Application title
  headerPanel("Healthcare"),

  # Sidebar with controls to select the variable to plot against mpg
  # and to specify whether outliers should be included
  sidebarPanel(
    selectInput("variable", "Factor: ",
                list("Uninsured %" = "uninsured", 
                     "Primary Care Physicians" = "primary_care_physicians", 
                     "Mental Health Providers" = "mental_health_providers",
                     "Dentists" = "dentists"
                     ))
  ),

  mainPanel(
    plotOutput("yearPlot"))
))

shinyServer(function(input, output) {

      output$yearPlot <- renderPlot({
        ggplot(insurance, aes(year, input$variable, color = County)) + geom_point() + geom_line() 
      })

    })

我的输出是这样的:

在此处输入图像描述

我要这个:

在此处输入图像描述

我不知道问题出在哪里,因为应该根据我的数据集定义数值变量。但不知何故,我的变量在 y 轴的图表上减少到只有一个点。

标签: rggplot2shiny

解决方案


推荐阅读