In my below code, I have a checkbox which when checked plots a curve over the data using geom_smooth. However, I also have a second check box which when checked introduces a colouring aesthetic and colours some of the data red and some black. The problem is that when both boxes are checked I get two curves, one for the black data and one for the red, but would like the curve to stay as the 'total' curve at all times.
library(ggplot2)
library(shiny)
library(shinyWidgets)
ui <- fluidPage(
titlePanel("Transfers Analysis App"),
sidebarLayout(
sidebarPanel(
pickerInput(inputId = "Day",
label = "Days of Week",
choices = c("Monday", "Tuesday", "Wednesday", "Thursday", "Friday", "Saturday"), selected = data$day[data$day %in% c('Monday', 'Tuesday', 'Wednesday', 'Thursday', 'Friday', 'Saturday')],
options = list(`actions-box` = TRUE),
multiple = T),
pickerInput(inputId = "Month",
label = "Months",
choices = c("January", "February", "March", "April", "May", "June", "July", "August", "September", "October", "November", "December"), selected = data$month[data$month %in% c('January', 'February', 'March', 'April', 'May', 'June', 'July', 'August', 'September', 'October', 'November', 'December')],
options = list(`actions-box` = TRUE),
multiple = T),
checkboxInput("Outage", "Highlight Days when an Outage Occured", FALSE),
checkboxInput("Curve", "Curve of Best Fit", FALSE)),
mainPanel(
plotOutput("plot1", height = "600px", width = "100%",
hover = hoverOpts(id = "plot_hover")),
verbatimTextOutput("hover_info")
)))
server <- function(input, output) {
output$plot1 <- renderPlot({
Day <- input$Day
Month <- input$Month
Outage <- input$Outage
COBF <- input$Curve
data <- data[data$day %in% input$Day]
data <- data[data$month %in% input$Month]
g <- ggplot(data, aes(Date, NUMBER_OF_TRANSFERS)) + geom_point()
if (COBF == TRUE)
g <- g + geom_smooth()
if (Outage == TRUE)
g <- g + aes(colour = Incident) + scale_colour_manual(values=c( "red", "black"))
#if(Outage == TRUE)
# ggplot(data, aes(Date, NUMBER_OF_TRANSFERS, colour = Incident)) + geom_point() + scale_colour_manual(values=c( "red", "black"))
#else
# ggplot(data, aes(Date, NUMBER_OF_TRANSFERS)) + geom_point()
#points(data$Date[data$Quantity == "1"],data$NUMBER_OF_TRANSFERS[data$Quantity == "1"], col='red')
plot(g)
})
}
shinyApp(ui, server)