Timeseries graph with dual Y axis with different scales

14 Views Asked by At

I have stumbled upon an error in my code that reads as follows: 'Error in scale_y_axis1(labels = scales::comma): could not find function "scale_y_axis1"'. Can you please help me figure out how to fix this error?

# Load libraries


library(readxl)
library(ggplot2)


# Read data from Excel file
data <- read_excel("C:/Users/WINDOWS 10/Desktop/Results/Data/Clay Loam 2/CL2 Soil moisture and NDVI.xlsx")

# Select variables of interest
soil_moisture <- data$CL2Soilmoisture
NDVI <- data$CL2NDVI
date <- data$Date

# Create time series chart with dual Y-axis
ggplot(data, aes(x = date)) +
  geom_line(aes(y = soil_moisture), color = "blue") +
  geom_line(aes(y = NDVI), color = "red") +
  scale_y_axis1(labels = scales::comma) +
  scale_y_axis2(labels = scales::comma, trans = function(x) x * 10) +
  labs(title = "Comparison of Soil Moisture and NDVI", x = "Date", y = "Value") +
  theme_bw()

I am currently working on analyzing time series data in R to compare soil moisture and NDVI. My goal is to create a line graph that displays two dual axes with different scales. but keep getting an error in the code.

0

There are 0 best solutions below