ggplot aes_字符串在r应用程序中不采用x轴和y轴
我正在尝试构建一个基于日期过滤的r闪亮应用程序。但ggplot并没有选取x和y值,而且当我将过滤后的数据输出为表格时,还有一个数字显示在日期的位置ggplot aes_字符串在r应用程序中不采用x轴和y轴,r,ggplot2,shiny,R,Ggplot2,Shiny,我正在尝试构建一个基于日期过滤的r闪亮应用程序。但ggplot并没有选取x和y值,而且当我将过滤后的数据输出为表格时,还有一个数字显示在日期的位置 data2$Deployment.Month<- as.Date(data2$Deployment.Month,format = "%d-%m-%Y") min_date <- min(data2$Deployment.Month) max_date <- max(data2$Deployment.Month) data3 <
data2$Deployment.Month<- as.Date(data2$Deployment.Month,format = "%d-%m-%Y")
min_date <- min(data2$Deployment.Month)
max_date <- max(data2$Deployment.Month)
data3 <- as.data.frame(data2)
data4<- na.omit(data3)
ui <- fluidPage(
sidebarLayout(
# Input(s)
sidebarPanel(
# Select variable for x-axis
selectInput(inputId = "x",
label = "Variable 1",
choices = c(choices),
selected = "Project.Id"),
# Select variable for y-axis
selectInput(inputId = "y",
label = "Variable 2",
choices = c(choices),
,
dateRangeInput(inputId = "date",
label = "Select dates:",
start = "2013-01-01",
end = "2017-12-31",
startview = "year",
min = as.Date(min_date), max = as.Date(max_date))),
mainPanel(plotOutput(outputId = "scatterplot"),tableOutput("table"))))
server<- function(input, output){
output$scatterplot <- renderPlot({req(input$date)
projects_selected_date <- data4 %>%filter(Deployment.Month >= input$date[1] & Deployment.Month <=input$date[2])
ggplot(projects_selected_date,aes_string(x=projects_selected_date$x,y=projects_selected_date$y),colour='red')+ geom_point()})
output$table <- renderTable({
projects_selected_date <- data4 %>% filter(Deployment.Month >= input$date[1] & Deployment.Month <= input$date[2])
projects_selected_date})}
# Create a Shiny app object
shinyApp(ui = ui, server = server)
data2$Deployment.Month我需要更多元素来执行完美的代码,但请尝试以下代码:
data4<- na.omit(data3)
ui <- fluidPage(
sidebarLayout(
# Input(s)
sidebarPanel(
# Select variable for x-axis
selectInput(inputId = "x",
label = "Variable 1",
choices = c("Col1", "Col2", "Col3"), # You have to define colnames
selected = "Col1"),
# Select variable for y-axis
selectInput(inputId = "y",
label = "Variable 2",
choices = c("Col4", "Col5", "Col6"), # Same things
selected = "Col4"),
mainPanel(plotOutput(outputId = "scatterplot"),
tableOutput("table")
)
)
)
server<- function(input, output){
output$scatterplot <- renderPlot({
projects_selected_date <- data4 %>%filter(Deployment.Month >= input$date[1] & Deployment.Month <=input$date[2])
ggplot(projects_selected_date,aes_string(x = input$x ,y = input$y,colour='red')) + geom_point()
})
### I don't know if this piece of code works !
output$table <- renderTable({
projects_selected_date <- data4 %>% filter(Deployment.Month >= input$date[1] & Deployment.Month <= input$date[2])
table(projects_selected_date)
)}
# Create a Shiny app object
shinyApp(ui = ui, server = server)
data4您应该编辑代码。很难跟进。您还应该提供一个可复制的示例。您的ggplot()
绘图的中缺少%%
。请勿在aes
中使用$,我正在使用:projects\u selected\u date%filter(Deployment.Month>=input$date[1]筛选数据&Deployment.Month基本上,您不应该在aes
中使用$。ggplot可以直接从数据帧中找到变量。为什么您在不使用字符串的情况下使用aes_字符串?示例中的所有闪亮命令都可以删除,不需要重新生成。