r - 像直线一样闪亮的散点图
问题描述
我正在使用 selectInput 从用户那里获取输入,而 Shiny 应用程序将获得的输入是我的 data.frame 中的列名。然后在渲染图中,我尝试通过将 x 轴作为选定列并将 y 轴作为其他固定列来绘制散点图。我的数据看起来像这样
我闪亮的代码:
# Define UI for application that draws a histogram
ui <- fluidPage(
# Application title
titlePanel("Old Faithful Geyser Data"),
selectInput(inputId = "ghg", label = "Choose a Coral type",
c("CO2" = "CO2_emissions",
"Methane" = "methane_emissions",
"Nitrous Oxide" = "nitrous_oxide",
"Other" = "HFC_PFC_SF6")),
# Show a plot of the generated distribution
mainPanel(
plotOutput("distPlot")
)
)
# Define server logic required to draw a histogram
server <- function(input, output) {
output$distPlot <- renderPlot({
climate_change <- read_excel('climate_change_global.xlsx')
gg <- ggplot(climate_change, aes(x=input$ghg, y=temp)) + geom_point() +
geom_smooth(method="lm") + ggtitle("CO2 corelation with temperature is 91%")
gg
})
}
# Run the application
shinyApp(ui = ui, server = server)
自过去 4 天以来,我一直在尝试解决此问题,但我无法解决。请帮忙。
解决方案
您的代码将input$ghg
内部aes()
作为列本身,而不是作为具有列名的字符串。这就是为什么它在 x 轴上只有一个值。
因此x = !!as.name(input$ghg)
,x = !!sym(input$ghg)
您需要x = get(input$ghg)
在aes()
.ggplot
推荐阅读
- c# - IdentityUserLogin 的实现
- sql-server - 从两个表中获取不同的值
- python - 如何在训练 XGBoost 模型时使用 GPU?
- python - Django 错误 - 不支持的操作数类型 -: 'str' 和 'int'
- networking - Freeradius 额外开放端口
- python - 使用 python matplotlib 创建水平瀑布图
- angular - 提交包含注册和提交的响应式表单,并在不使用服务但使用路由的情况下在网格中显示数据
- javascript - 获取滚动div的位置并检测滚动到哪个元素
- dom - 如何防止 cy.get 在排序之前“快照”列表
- stackedit - 更改 StackEdit 格式