ggplot将我的所有数据绘制到一行中

问题描述

我正在制作一个显示x和y输入的仪表板。但是,当两个输入都传递时,ggplot将我的数据绘制为单线。我也尝试使用plotly,但完全没有结果。有人能够帮助您使用有效的ggplot和绘图示例。

这是ggplot代码部分加上图像结果

renderPlot({
   p <- ggplot(Merged_data_frame_hcat,aes_string(x=input$x,y=input$y)) + geom_point()
 
   print(p)
  
})

enter image description here

以及代码和图像

renderPlot({
  p <- plot_ly(data= Merged_data_frame_hcat,x= ~input$x,y= ~input$y,type = 'scatter',mode = 'lines' )
 
   print(p)
  
})

enter image description here

解决方法

要调试代码,可以使用cat打印控制台中正在使用的数据,例如:

renderPlot({
   cat('input$x=',input$x,'\n')
   p <- ggplot(Merged_data_frame_hcat,aes_string(x=input$x,y=input$y)) + geom_point()
   print(p)
  
})

如果您查看RStudio控制台,则会看到要传递给aes_string的值。
从评论中的答案中,您很可能会在控制台中看到:

shinyApp(ui = ui,server = server)

Listening on http://127.0.0.1
input$x = 1

这是由于selectInput works的方式造成的:

选择:要选择的值列表。 如果已命名列表中的元素,则会向用户显示该名称---而不是值---。

这意味着如果

choices = list('dates'=1)

您在dates中看到selectInput,并在1中看到input$x
如@MrFlick在第一条评论中所指出的,要获得进一步的帮助,您需要提供一个简单的reproducible example:主要通过评论来发现和解决问题效率不高。

相关问答

依赖报错 idea导入项目后依赖报错,解决方案:https://blog....
错误1:代码生成器依赖和mybatis依赖冲突 启动项目时报错如下...
错误1:gradle项目控制台输出为乱码 # 解决方案:https://bl...
错误还原:在查询的过程中,传入的workType为0时,该条件不起...
报错如下,gcc版本太低 ^ server.c:5346:31: 错误:‘struct...