0

I have the following code written for r shiny. The legend doesn't show up. Is there a better way to have this data plotted? Could you please tell me how to show the legend in the graph?

 data <- gsheet2tbl(xxx)
    
   data1 <-  data  %>%
            mutate(Date = dmy(Date))

output$Plot <- renderPlot({
        data1 %>% filter(Name == input$Name)%>%
        ggplot(aes(x= Date))+  
        geom_line(aes(y= S_Fast), color= "Blue", show.legend = )+ geom_point(aes(y= S_Fast),size = 3 , col= "Blue")+ 
        geom_line(aes(y= S_Post), color = "Red")+ geom_point(aes(y= Sugar_Post), size = 3 ,  col = "Red")+
        geom_line(aes(y= weight), color = "Brown")+ geom_point(aes(y= weight), size = 3 ,  col = "Brown")+
       
        
        labs(title = paste('Details of Test Score for', input$Name), 
             x =  'Date', 
             y = 'Test Scores')
    
Phil
  • 7,287
  • 3
  • 36
  • 66
Reju V S
  • 17
  • 1
  • 5
  • 1
    In the current way you have things set up you'll want to put the color aesthetic inside `aes()` to get a legend. I have a blog post about it if you are interested: https://aosmith.rbind.io/2018/07/19/manual-legends-ggplot2/ – aosmith Mar 10 '21 at 19:22
  • 1
    Does this answer your question? [Add legend to ggplot2 line plot](https://stackoverflow.com/questions/10349206/add-legend-to-ggplot2-line-plot) – stefan Mar 10 '21 at 21:17

0 Answers0