######################################################Figure 1 met####################################### data<- read.csv("met two.csv") if(!require(ggplot2)) install.packages("ggplot2") if(!require(lubridate)) install.packages("lubridate") if(!require(dplyr)) install.packages("dplyr") library(ggplot2) library(lubridate) library(dplyr) data <- read.csv("met two.csv") data$Date <- as.Date(data$Date) data$Month <- floor_date(data$Date, "month") monthly_data <- data %>% group_by(Month) %>% summarise( Total_Rainfall = sum(Rainfall, na.rm = TRUE), Avg_Temperature = mean(Temperature, na.rm = TRUE) ) p1 <-ggplot(monthly_data, aes(x = Month)) + geom_bar(aes(y = Total_Rainfall), stat = "identity", fill = "blue", alpha = 0.6) + geom_line(aes(y = (Avg_Temperature + 15) * 2), color = "red", size = 1) + scale_y_continuous(expand = c(0,0), name = "Rainfall (mm)", sec.axis = sec_axis(~./2 - 20, name = "Temperature (°C)", breaks = seq(-20, 50, by = 10)), limits = c(0, 140) ,breaks = seq(0, 140, by = 20) ) + scale_x_date( date_labels = "%Y-%m", date_breaks = "4 months", limits = as.Date(c("2020-01-01", "2021-12-31")) ) + labs( x = "Month") + theme_minimal() + theme( axis.title.y.left = element_text(color = "blue"), axis.title.y.right = element_text(color = "red") )+mytheme2 ggsave("met.png", plot=p1, height=10, width=15, units="cm", dpi=600)