inst/shiny/plotComp1.R

output$plotComp1 <- renderPlot({
  
  regDat <- getRegDat()
  
  bestOffsetVal <- getBestOffset(regDat) 
  
  yvar <- paste0("y-", input$yID)
  
  xvar <- paste0("x-", input$xID)
  
  cols = c(yvar = "blue", 
           xvar = "green")
  
  if(input$lag1 == 0) {
    
    if (input$log10 == FALSE) {
      
      p <- ggplot() +
        geom_line(data = regDat, aes(x = dateTime, y = Flow.y, color = yvar), size = 1) +
        geom_rect(aes(xmin = as.POSIXct(input$estDateSt, format = "%Y-%m-%d %H:%M:%S", tz = "GMT"), 
                      xmax = as.POSIXct(input$estDateEn, format = "%Y-%m-%d %H:%M:%S", tz = "GMT"), 
                      ymin = -Inf, ymax = Inf), alpha = 0.4, color = "grey50") +
        geom_line(data = regDat[!is.na(regDat$Flow.x),], aes(x = dateTime, y = Flow.x, color = xvar), size = 1, linetype = "dotdash") +
        labs(x = "Date (UTC)", y = "Discharge, in cubic feet per second",
             title = paste0("calculated best time offset = ", bestOffsetVal, " minutes")) +
        #scale_color_manual(values = cols) +
        theme_bw() + theme(legend.title = element_blank())
      
    }
    
    else if (input$log10 == TRUE) {
      
      p <- ggplot() +
        geom_line(data = regDat, aes(x = dateTime, y = Flow.y, color = yvar), size = 1) +
        geom_rect(aes(xmin = as.POSIXct(input$estDateSt, format = "%Y-%m-%d %H:%M:%S", tz = "GMT"), 
                      xmax = as.POSIXct(input$estDateEn, format = "%Y-%m-%d %H:%M:%S", tz = "GMT"), 
                      ymin = 0, ymax = Inf), alpha = 0.4, color = "grey50") +
        geom_line(data = regDat[!is.na(regDat$Flow.x),], aes(x = dateTime, y = Flow.x, color = xvar), size = 1, linetype = "dotdash") +
        scale_y_log10() +
        annotation_logticks(sides = "rl") +
        labs(x = "Date (UTC)", y = "Discharge, in cubic feet per second", 
             title = paste0("calculated best time offset = ", bestOffsetVal, " minutes")) +
        #scale_color_manual(values = cols) +
        theme_bw() + theme(legend.title = element_blank(), panel.grid.minor = element_blank())
      
    }
    
    p
    
  }
  
  else if(input$lag1 != 0) {
    
    if (input$log10 == FALSE) {
      
      p <- ggplot() +
        geom_line(data = regDat, aes(x = dateTime, y = Flow.y, color = yvar), size = 1) +
        geom_rect(aes(xmin = as.POSIXct(input$estDateSt, format = "%Y-%m-%d %H:%M:%S", tz = "GMT"), 
                      xmax = as.POSIXct(input$estDateEn, format = "%Y-%m-%d %H:%M:%S", tz = "GMT"), 
                      ymin = -Inf, ymax = Inf), alpha = 0.4, color = "grey50") +
        geom_line(data = regDat[!is.na(regDat$Flow.x),], aes(x = dateTime, y = Flow.x, color = xvar), size = 1, linetype = "dotdash") +
        labs(x = "Date (UTC)", y = "Discharge, in cubic feet per second") +
        #scale_color_manual(values = cols) +
        theme_bw() + theme(legend.title = element_blank())
      
    }
    
    else if (input$log10 == TRUE) {
      
      p <- ggplot() +
        geom_line(data = regDat, aes(x = dateTime, y = Flow.y, color = yvar), size = 1) +
        geom_rect(aes(xmin = as.POSIXct(input$estDateSt, format = "%Y-%m-%d %H:%M:%S", tz = "GMT"), 
                      xmax = as.POSIXct(input$estDateEn, format = "%Y-%m-%d %H:%M:%S", tz = "GMT"), 
                      ymin = 0, ymax = Inf), alpha = 0.4, color = "grey50") +
        geom_line(data = regDat[!is.na(regDat$Flow.x),], aes(x = dateTime, y = Flow.x, color = xvar), size = 1, linetype = "dotdash") +
        scale_y_log10() +
        annotation_logticks(sides = "rl") +
        labs(x = "Date (UTC)", y = "Discharge, in cubic feet per second") +
        #scale_color_manual(values = cols) +
        theme_bw() + theme(legend.title = element_blank(), panel.grid.minor = element_blank())
      
    }
    
    p
    
  }
  
})
bbreaker-usgs/MISTEuv documentation built on May 11, 2019, 9:30 p.m.