Note that there are some explanatory texts on larger screens.

plurals
  1. POggplot2 wind time series with arrows/vectors
    primarykey
    data
    text
    <p>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).</p> <p><img src="https://i.stack.imgur.com/7lvPm.png" alt="enter image description here"></p> <p>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.</p> <p>Thanks in advance</p> <p><strong>EDIT QUESTION</strong> 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. </p> <p>Here is the code used for the plot (temperature) and <a href="http://ubuntuone.com/4Hb222VX1Scfv4TabqD8v5" rel="noreferrer">data</a> </p> <pre><code>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 (ºC)") + 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) } </code></pre> <p>Following geom_segment docs I tried</p> <pre><code>p=ggplot(tore, aes(x =datetime, y = 5)) p + geom_segment(aes(xend = datetime, yend = 5 + v), arrow = arrow(length = unit(0.1,"cm"))) </code></pre> <p>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"</p> <p><img src="https://i.stack.imgur.com/QUoD2.png" alt="enter image description here"></p> <p>Thanks for your help</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload