options(width = 120) df <- read.csv("data.csv",col.names=c("DateTime", "DB", "RH","DP","P","WIND","WIND-DIR","SUN","RAIN","START")) df=df[complete.cases(df), ] df$datetime=as.POSIXct(df$DateTime, format = "%d/%m/%Y %H:%M") df=subset(df, format(datetime, "%m") == "08" & format(datetime, "%Y") == "2003") head(df) df$DB=(df$DB/10) df$RH=(df$RH/100) df$P=(df$P*100) df$datetime[which.min(df$DB)] print(df[which(df$DB == min(df$DB)), ]) volFlow=1.0 airDensity=0.123 massFlow=volFlow*airDensity airHeatCapacity=1000 setpoint=22 IDT=22 HRE1=0.0 HRE2=0.00 df$airOn1=(HRE1*(IDT))-((df$DB)*(HRE1-1)) df$airOn2=(HRE2*(IDT))-((df$DB)*(HRE2-1)) df$Q1=massFlow*airHeatCapacity*(setpoint-df$airOn1) df$Q2=massFlow*airHeatCapacity*(setpoint-df$airOn2) #HTG=quantile(df$Q[which(df$Q>=0)], probs = 0.996) #print(HTG) print(min(df$Q)) print(max(df$Q)) #CLG=quantile(df$Q[which(df$Q<=0)], probs = 0.004) head(df,n=100) library(ggplot2) # Create line chart p <- ggplot(df,aes(x=datetime)) + # geom_line(aes(y = Q1, color =ifelse(Q1>0,"blue","red")))+ geom_line(aes(y = Q2))+ geom_area(fill = "red", aes(y = pmax(Q2, 0)))+ geom_area(fill = "blue", aes(y = pmin(Q2, 0)))+ # geom_hline(yintercept = HTG)+ # geom_hline(yintercept = CLG)+ ylim(-3000,3000) # Save plot to PDF ggsave("line_chartJ.pdf", p, width = 16, height = 6)