Data Preparation

#Change to numeric value
cols.num <- c("pH","Salinity", "..3","Population \r\nMale / Female","Mortalities\r\nMale / Female","..5","Molts")
data[cols.num] <- sapply(data[cols.num],as.numeric)

#Change variable names
library(data.table)
setnames(data, c("Population \r\nMale / Female","..3","Total Ammonia Nitrogen                       (ppm)"), new = c("Population_male","Population_female","TAN"))

#Attach data
head(data)
## # A tibble: 6 x 20
##   Date                Population_male Population_fema~ `Mortalities\r\~
##   <dttm>                        <dbl>            <dbl>            <dbl>
## 1 2018-10-05 00:00:00              16               14                0
## 2 2018-10-06 00:00:00              16               14                0
## 3 2018-10-07 00:00:00              16               14                0
## 4 2018-10-08 00:00:00              16               14                0
## 5 2018-10-09 00:00:00              30               30                0
## 6 2018-10-10 00:00:00              30               30                0
## # ... with 16 more variables: ..5 <dbl>, Molts <dbl>,
## #   `Ripe\r\nFemale` <chr>, `Mated\r\nFemale` <dbl>,
## #   `Spawned\r\nFemale` <dbl>, Ripe <chr>, Mated <chr>, Spawned <chr>,
## #   Dead <chr>, `Pump VFD` <dbl>, `Flow Rate (GPM)` <chr>, `Excess Feed
## #   (g)` <chr>, pH <dbl>, D.O. <chr>, Salinity <dbl>, TAN <dbl>

Subset data to current 30 days

library(lubridate)
data1 <- subset(data,Sys.Date() >= data$Date & data$Date >= Sys.Date()-30)
head(data1)
## # A tibble: 6 x 20
##   Date                Population_male Population_fema~ `Mortalities\r\~
##   <dttm>                        <dbl>            <dbl>            <dbl>
## 1 2019-03-18 00:00:00              25               25                0
## 2 2019-03-19 00:00:00              25               25                0
## 3 2019-03-20 00:00:00              25               25                0
## 4 2019-03-21 00:00:00              25               25                0
## 5 2019-03-22 00:00:00              25               25                0
## 6 2019-03-23 00:00:00              25               25                0
## # ... with 16 more variables: ..5 <dbl>, Molts <dbl>,
## #   `Ripe\r\nFemale` <chr>, `Mated\r\nFemale` <dbl>,
## #   `Spawned\r\nFemale` <dbl>, Ripe <chr>, Mated <chr>, Spawned <chr>,
## #   Dead <chr>, `Pump VFD` <dbl>, `Flow Rate (GPM)` <chr>, `Excess Feed
## #   (g)` <chr>, pH <dbl>, D.O. <chr>, Salinity <dbl>, TAN <dbl>

Loess smoothing line

library(devtools)
#devtools::install_github("tidyverse/ggplot2")
library(tidyverse) # Load all "tidyverse" libraries.
# OR
# library(readr)   # Read tabular data.
# library(tidyr)   # Data frame tidying functions.
# library(dplyr)   # General data frame manipulation.
# library(ggplot2) # Flexible plotting.
library(ggplot2)
library(scales)
library(purrr)

data1$Date <- as.Date(data1$Date)

library(scales)
library(ggthemes) # theme
ggplot(data1, aes(Date,TAN)) +
  geom_point(shape=3) + 
  geom_smooth(colour="orange", size=0.5) +
  theme_stata() + 
  scale_color_stata()+
  scale_x_date(date_breaks = "2 day", labels=date_format("%m-%d")) +
  theme(axis.text.x=element_text(angle=45, hjust=1)) +
  ggtitle("TAN (Total Ammonia Nitrogen)")