2 graphs in one plot in shiny not showing lines on geom_line

Good day, have been trying to make this work with no luck so far, for some reason it is not displaying lines only points,tried using only geom_line instead of geom_point also.

PlotData is a reactive value and it creates a dataframe

output$scat=
  renderPlot({
    ggplot(plotData())+
      geom_point(aes(x=Weeks,y=Vtas4,color='blah',size=2))+
      geom_line(aes(x=Weeks,y=Vtas4,color="blah1"))+
      #redplot
      geom_point(aes(x=Weeks,y=Fcst4,color='blahx',size=2))+
      geom_line(aes(x=Weeks,y=Fcst4,color="blahx1"))+
      scale_color_manual(values=c(blah='blue','blah1'='blue',blahx='red','blahx1'='red'))
})

also used colour insted of color in geom_line
thanks a lot.

Hey @Valholy - thanks for posting! When asking questions about code problems, it's good to try to create a reproducible example, if at all possible. See: FAQ: Tips for writing R-related questions. Can you post an example including some data that we could reproduce?

It's hard to know for sure without a reprex and sample data but maybe Vtas4 and Fcst4 are not numerical variables, that would explain why geom_point works and geom_line doesn't.

thanks a lot , hold on will create an example

heres the reproducible example:

library(shiny)
library(DT)
library(RODBC)
library(shinythemes)
library(shinydashboard)
library(ggplot2)

ui=navbarPage(theme=shinytheme("sandstone"),title=h6("App Tienda V2"),
              tabPanel(
                ("Consulta"),
                sidebarPanel(
                  textInput("Tienda","Tienda"),
                  textInput("depto","depto"),
                  textInput("Articulo","Articulo"),
                  actionButton("mybutton","Consultar Tienda")
                ),
                mainPanel(
                  plotOutput("scat")
                  
                ),
                DT::dataTableOutput("tableDT1")
                
                
              ),
              tabPanel(("DETALLE"),
                       DT::dataTableOutput("tableDT")),
              
              tabPanel(("text"),
                       fluidPage(
                         fluidRow(
                           column(2,box(verbatimTextOutput("Store_Nbr"), status = "primary", solidHeader = FALSE, collapsible = FALSE, width = 9, title = "DET")),
                           column(2,box(verbatimTextOutput("Store_Name"), status = "primary", solidHeader = TRUE, collapsible = FALSE, width = 9, title = "TIENDA")),
                           column(2,box(verbatimTextOutput("Old_Nbr"), status = "primary", solidHeader = TRUE, collapsible = FALSE, width = 9, title = "ARTICULO"))
                         ),
                         
                         fluidRow(
                           column(2,box(verbatimTextOutput("UPC"), status = "primary", solidHeader = FALSE, collapsible = FALSE, width = 9, title = "DET")),
                           column(2,box(verbatimTextOutput("Dept_Nbr"), status = "primary", solidHeader = TRUE, collapsible = FALSE, width = 9, title = "TIENDA")),
                           column(2,box(verbatimTextOutput("Category_Nbr"), status = "primary", solidHeader = TRUE, collapsible = FALSE, width = 9, title = "ARTICULO"))
                         )
                         
                         
                       )  
                       
              ))


server=function(input,output,session){
  
  
  
  origTable_selected <- reactive({
    ids <- input$tableDT1_rows_selected
  })
  
  output$Store_Nbr=renderText({mtcars[origTable_selected(),1]})
  output$Store_Name=renderText({toString(mtcars[origTable_selected(),2])})
  output$Old_Nbr=renderText({mtcars[origTable_selected(),3]})
  output$UPC=renderText({mtcars[origTable_selected(),4]})
  output$Dept_Nbr=renderText({mtcars[origTable_selected(),5]})

  
  output$tableDT1=DT::renderDataTable(mtcars[1:nrow(mtcars),],
                                      options=list(paging=T),
                                      rownames=F,
                                      filter="top",
                                      selection="single")
  
  plotData=reactive({
    wks=c("Current","Wk1","Wk2","Wk3")
    vtas=c(mtcars[origTable_selected(),1],mtcars[origTable_selected(),2],mtcars[origTable_selected(),3],
           mtcars[origTable_selected(),4])
    fcst=c(mtcars[origTable_selected(),5],mtcars[origTable_selected(),6],mtcars[origTable_selected(),7],
           mtcars[origTable_selected(),8])
    dats=data.frame(wks,vtas,fcst)
    colnames(dats) <- c("Weeks","Vtas4", "Fcst4")
    return(dats)
  })
  
  output$scat=renderPlot({
    ggplot(plotData())+
      geom_point(aes(x=Weeks,y=Vtas4,color='blah',size=2))+
      geom_line(aes(x=Weeks,y=Vtas4,color="blah1"))+
      #redplot
      geom_point(aes(x=Weeks,y=Fcst4,color='blahx',size=2))+
      geom_line(aes(x=Weeks,y=Fcst4,color="blahx1"))+
      scale_color_manual(values=c('blah'='blue','blah1'='blue','blahx'='red','blahx1'='red'))
  })
  
  
  
}
shinyApp(ui=ui,server=server)

thanks a lot

This topic was automatically closed 54 days after the last reply. New replies are no longer allowed.

If you have a query related to it or one of the replies, start a new topic and refer back with a link.