r - ggplot2 wind time series with arrows/vectors -


from meteorological data (hourly values of temperature, wind , humidity) managed plot time series of wind speed , direction. add wind vectors on time series plot. here can see output (arrows drawn on actual plot).

enter image description here

i using ggplot2, been looking through stackoverflow, ggplot2 package docs (will continue) no solution found. idea or indication starting point.

thanks in advance

edit question suggested in comment @slowlearner add here code , data make reproducible example. looks geom_segment trick. managed calculate yend in geom_segment can't figure out how find xend x axis time axis. i've got wind speed , direction data can calculate x,y wind components geom_segment x needs converted time format.

here code used plot (temperature) , 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 (º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), = 2),0))   ggsave(myplot,filename=paste("rams-",i,".png",sep=""),width=7.78,height=5.79)  } 

following geom_segment docs 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 kind of figure. can see x coordinate datetime, how should convert wind component xend? xend equals datetime "datetime + xwindcomp"

enter image description here

thanks help

just preamble, please make sure include code , relevant data in future questions. if @ question above, see objects such torre not defined. means can't copy , paste our r setups. data linked not used code in question limited subset. advice: (a) create fake data looks data using (b) keep code absolute minimum (c) test , double-check code , data in new r session before post.

as far can tell want below. of course have adapt own purposes, should give ideas on how tackle problem. notice of cosmetic properties such line colours, thicknesses, legends , titles have been omitted plot: not important purposes of question. edit approach might use same data frame wind data , use faceting variable show speed in different linked plot.

require(ggplot2) require(scales) require(gridextra) require(lubridate) set.seed(1234)  # create fake data temperature mydf <- data.frame(datetime = isodatetime(2013,08,04,0,0,0) +                    seq(0:50)*10*60,                    temp = runif(51, 15, 25))  # take subset of temperature data, # sampling every 60 minutes wind <- mydf[minute(mydf$datetime) == 0, ] # create fake wind velocity data wind$velocity <- runif(nrow(wind), -5, 20) # define end point geom_segment wind$x.end <- wind$datetime + minutes(60)  ggplot(data = mydf, aes(x = datetime, y = temp, group = 1)) +     geom_line() +     geom_segment(data = wind,                  size = 3,                  aes(x = datetime,                      xend = x.end,                      y = 10,                      yend = velocity),                  arrow = arrow(length = unit(0.5, "cm"))) +     theme() 

this generates following plot: screenshot


Comments

Popular posts from this blog

image - ClassNotFoundException when add a prebuilt apk into system.img in android -

I need to import mysql 5.1 to 5.5? -

Java, Hibernate, MySQL - store UTC date-time -