I have a wind speed and direction times series and I am trying to make a plot that uses line segments to depict the windspeed and direction. I need to have a basic point scatter plot of windspeed vs time (which I can create) with a line segment from each point (which is where I am getting hung up.) The length of the line has to be proportional to the windspeed and the angle needs to the wind direction. I am using ggplot2 with the geom_segment, but because x is time I cannot figure the right formula to use for xend.
Here is an example of the dataframe:
Here is my code so far:
library(ggplot2)
library(lubridate)
Gustav <- read.csv("C:/Users/ezco3/My Research/LPBF/Pontchartrain-Maurepas Surge Consortium/Projects/Lake Tilting Effect Graphic/Datasets/Gustav_NewCanal_Hydro&Metero.csv")
Gustav$TS <- as.POSIXct(Gustav$DateTime, "%m/%d/%Y %H:%M", tz="America/Chicago")
Gustav$DelY <- Gustav$WINDSPEED_MPH*sin(Gustav$DIR)/max(Gustav$WINDSPEED_MPH, na.rm=TRUE)
Gustav$DelX <- Gustav$WINDSPEED_MPH*cos(Gustav$DIR)/max(Gustav$WINDSPEED_MPH, na.rm=TRUE)
plt1 <- ggplot(data = Gustav, aes(x = TS, y =WINDSPEED_MPH))
plt1 + geom_point(color="blue") +
geom_segment(data = Gustav, mapping=aes(x= TS, y = WINDSPEED_MPH, xend = TS + 18000*DelX,
yend=WINDSPEED_MPH + 5*DelY),size=.1,color="red")
The 18000 in front of DelX and the 5 in front of DelY are both arbitrary numbers that I found through trail and error. Basically, initially using just DelX and DelY (without multipliers) the lines were short and vertical, so I worked through different option until I found this pair which showed some direction to the line.
However, the angles are not correct. At this stage, I do not understand how units work with time series objects in lubridate so I am lost as to how to figure the correct formula for xend.
Any advice would be much appreciated.
Thanks!!!

dput(Gustav)into your question. You don't need to paste the whole thing. 10 or 20 rows (e.g.,dput(Gustav[1:20,])) should be enough. - eipi10DelXby the ratio of range of the xaxis to range of the yaxis. To get this exact, you should usecoord_cartesianto set the x and y axis ranges and then take the ratio of their ranges as the scale factor. - eipi10