From meteorological data (hourly values of temperature, wind and humidity) I managed to plot time series of wind speed and direction. Now I would like to add wind vectors on the time series plot. Here you can see the output I would like (arrows drawn over the actual plot).
I am using ggplot2, been looking through stackoverflow, ggplot2 package docs (will continue) but no solution found. Any idea or indication where to look would be a starting point.
Thanks in advance
EDIT QUESTION
As suggested in a comment by @slowlearner I add here code and data to make a reproducible example. It looks like geom_segment could do the trick. I managed to calculate yend in geom_segment but can't figure out how to find xend as x axis is a time axis. I've got wind speed and direction data so I can calculate x,y wind components for geom_segment but x needs to be converted to time format.
Here is the code used for the plot (temperature) and data
for (i in 1:2 ) {
rams=subset(data,data$stat_id %in% i)
tore=subset(torre,torre$stat_id %in% i)
# Gràfica en ggplot
# Gráfica de evolución temporal de las estaciones de la zona
gtitol=places$nom[places$stat_id == i]
myplot=ggplot(data=rams,aes(x=datetime, y=tempc, colour="RAMS")) +
geom_line() + ylab("Temperatura (oC)") + xlab(" ") +
ggtitle(gtitol) + theme(legend.title=element_blank()) + theme(legend.position="bottom") +
scale_y_continuous(limits = c(0,40)) +
geom_line(data=tore,aes(x=datetime,y=temp,colour = "Torre"))
#scale_y_continuous(breaks = round(seq(min(data$tempc), max(data$tempc), by = 2),0))
ggsave(myplot,filename=paste("RAMS-",i,".png",sep=""),width=7.78,height=5.79)
}
Following geom_segment docs I tried
p=ggplot(tore, aes(x =datetime, y = 5))
p + geom_segment(aes(xend = datetime, yend = 5 + v), arrow = arrow(length = unit(0.1,"cm")))
Getting this kind of figure. You can see x coordinate is datetime, how should I convert wind component to get xend? By now xend equals datetime but I would like something like "datetime + xwindcomp"
Thanks for your help
See Question&Answers more detail:
os