Trying to scale the date on the x-axis of a time series plot so that it's more spaced out and readable. I have been using scale_x_date
to accomplish this but keep getting the following error message:
Invalid input: date_trans works with objects of class Date only
This is occurring despite initially defining date as Date
class in my dataset.
See example code below:
#Code Update 1 - August 29, 2020#
#load packages#
library(dplyr)
library(ggplot2)
library(tidyr)
library(lubridate)
library(scales)
#read dataset#
data = read.csv("WQ_long.csv")
#define variables#
as.factor(parameter)
as.numeric(value)
#as.Date(date,format="%m/%d/%y")
date <- as.Date(date, format="%m/%d/%y")
#define subset of data to make graph#
downstream = data %>%
filter(site %in% c("US1", "DS5", "DS10"))%>%
filter(parameter == "Al(d)")
#make plot #
plot = ggplot(data = downstream,
aes(x = date, y = value))+
geom_point(aes(color = site), size = 1.3)+
labs(x = "Date",
y = "Dissolved Aluminum (mg/L)",
title = "Dissolved Aluminum") +
theme_bw()+
scale_x_date(date_breaks = "5 days")
plot