library(ggplot2) library(ggpsychro) options(width = 150) 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$DB=(df$DB/10) df$RH=(df$RH/100) df$P=(df$P*100) library(psychrolib) SetUnitSystem("SI") df$HR=GetHumRatioFromRelHum(df$DB, df$RH, df$P) df$HR=(df$HR)*1000 head(df) df2 <- df[, c("DB", "HR")] head(df2) # Use chull on the x and y columns of df hull_indices <- chull(as.matrix(df2[, c("DB", "HR")])) head(hull_indices) # Print the indices of the points that make up the convex hull #print(hull_indices) # Use the indices to get the points themselves hull_points <- df2[hull_indices, ] centroid <- c(mean(hull_points$DB), mean(hull_points$HR)) print(centroid[1]) # Define the two points x1 <- min(hull_points$DB) y1 <- hull_points$HR[which.min(hull_points$DB)] x2 <- centroid[1] y2 <- centroid[2] print(x1) print(y1) print(x2) print(y2) # Calculate the slope and y-intercept m <- (y2 - y1) / (x2 - x1) c <- y1 - m * x1 print(m) print(c) # Print the points that make up the convex hull print(hull_points) p = ggpsychro(tdb_lim = c(-15, 40)) + geom_grid_relhum(alpha = 1.0, label.alpha = 1.0, label.size = 6, label.fontface = 2) + scale_relhum(minor_breaks = NULL) + geom_grid_wetbulb(size = 1.0, color = "black", alpha = 1.0, label_loc = NA) + scale_wetbulb(breaks = seq(25, 30, by = 5), minor_breaks = NULL) + geom_grid_vappres(label.size = 5) + scale_vappres(breaks = seq(6000, 7000, by = 500), limits = c(6000, 7000)) + geom_grid_specvol() + scale_specvol(labels = NULL) + geom_line(aes(x=c(-4.7,17),y=c(2.47,7)))+ geom_line(aes(x = 20:30, enthalpy = 64000, y=1,color="orange"), stat = "enthalpy") + geom_segment(x = -4.8, y = 2.47, xend = 17, yend = 7, color = "red")+ geom_polygon(data = hull_points, aes(x = DB, y = HR),color = "black", alpha = 0.2) + geom_point(aes(df$DB, relhum=df$RH),stat = "relhum",color = "red",size=0.1, )+ geom_grid_enthalpy() ggsave("chart.pdf", plot = p, width = 6, height = 4)