Wind Stick Plots in R

Hi,
I am trying to create a wind stick plot in R using three months of wind speed and direction data. I am having trouble doing this. Can anyone help me get started?

What have you tried?

Check out this perhaps?

I am confused on the data type that I am reading in. I have it in a csv file but am not sure if if my date and times are in the correct format

Can you provide a reproducible example? It will make it easier for people to help you and it will mean that you are more likely to get an answer.

this is some of the data I am trying to use

the code and error message I am getting is this:

set working directory

setwd("/Users/marybrandonscott/Desktop/GY 516/GY516")
read.csv('wind.csv')
fm<-read.csv("wind.csv")
u<- fm[["u"]]
v<- fm[["v"]]
xt<- fm[["dt"]]
t<-convertToDateTime(xt, origin = "1900-01-01")
plotSticks(t,3.0,u,v,yscale = 200, add = TRUE)
Error in u^2 : non-numeric argument to binary operator

Can you make it reproducible (not a screenshot)? Have another look at the article.

Perhaps enter paste the output from dput(head(fm)).

dt u v
1 20214.00 1.38930910 -1.490539e+01
2 20214.04 12.08651810 2.944432e+00
3 20214.08 11.62314509 6.688094e+00
4 20214.12 -13.93369189 -1.360967e+00
5 20214.17 1.51552555 -1.625952e+01
6 20214.21 3.49879941 1.734055e+01
7 20214.25 14.79958299 1.136521e+01
8 20214.29 18.10554240 -6.508989e+00
9 20214.33 -17.77981635 -1.002229e+01
10 20214.38 -17.16243585 8.696459e+00
11 20214.42 -1.63906111 1.604651e+01
12 20214.46 -15.63726033 -3.956386e+00
13 20214.50 5.51798393 -1.327917e+01
14 20214.54 14.53932141 -2.600199e+00
15 20214.58 -8.94487843 8.369686e+00
16 20214.62 -9.21802557 -5.413327e+00
17 20214.67 9.23357331 -6.461735e+00
18 20214.71 -8.88172716 -5.215834e+00
19 20214.75 -10.56321920 -6.203298e+00
20 20214.79 6.15648716 -1.059057e+01
21 20214.83 -10.11093076 -4.044895e+00
22 20214.88 -8.42046962 -6.585726e+00
23 20214.92 5.40793322 1.033005e+01
24 20214.96 11.81357013 1.048409e+00
25 20215.00 12.39129953 1.099680e+00
26 20215.04 9.24775658 7.101732e+00
27 20215.08 -4.61740221 8.107311e+00
28 20215.12 3.78462565 7.229261e+00
29 20215.17 -2.46927222 -6.965256e+00
30 20215.21 -7.06622524 1.328368e+00

put(head(fm))
structure(list(dt = c(20214, 20214.04167, 20214.08333, 20214.125,
20214.16667, 20214.20833), u = c(1.389309097, 12.0865181, 11.62314509,
-13.93369189, 1.515525555, 3.498799406), v = c(-14.90539232,
2.944432075, 6.688093769, -1.360966705, -16.25952282, 17.34054505
)), row.names = c(NA, 6L), class = "data.frame")

Better.

So what is the first date meant to be?

the first date is meant to be August 1. I have done this before but it was about two years ago. I remember I had to change the date and time to Julian Date

Sorry, how do you get 1 August from 20214? Even with the origin date that you set above of "1900-01-01", I get "1955-05-07".

library(tidyverse)
library(oce)

fm <- structure(list(dt = c(20214, 20214.04167, 20214.08333, 20214.125, 20214.16667, 20214.20833), 
                     u = c(1.389309097, 12.0865181, 11.62314509,13.93369189, 1.515525555, 3.498799406),
                     v = c(-14.90539232, 2.944432075, 6.688093769, -1.360966705, -16.25952282, 17.34054505
                     )),
                row.names = c(NA, 6L),
                class = "data.frame") %>% 
  as_tibble() %>% 
  mutate(dt = as.Date(dt, origin = "1900-01-01"))
# A tibble: 6 x 3
  dt             u      v
  <date>     <dbl>  <dbl>
1 1955-05-07  1.39 -14.9 
2 1955-05-07 12.1    2.94
3 1955-05-07 11.6    6.69
4 1955-05-07 13.9   -1.36
5 1955-05-07  1.52 -16.3 
6 1955-05-07  3.50  17.3 

I used a formula in excel to change the date to Julian date and it gave me 20214

I really don't know. Supposedly the origin for the Julian dates is 1970-01-01, but that doesn't seem to work.

I a, able to plot t vs p but I cannot seem to get the arrows on the plot. the message I am getting is:
fm<-read.csv("wind.csv")

u<- fm[["u"]]
p<- fm[["p"]]
v<- fm[["v"]]
xt<- fm[["dt"]]
t<-convertToDateTime(xt, origin = "1955-05-07")
oce.plot.ts(t,p)
plotSticks(t,2061, u, v, yscale=25, add = TRUE)
Warning message:
In arrows(as.numeric(x[ok]), y[ok], (as.numeric(x[ok]) + u[ok]/yscale/yrxr * :
zero-length arrow is of indeterminate angle and so skipped

okay so I figured it out, my scale was too small. I now need to clean up the arrows.


image 1 is what I have made but I am trying to clean it up like image 2. I am not using water level so I do not need that information. My arrows just seem like they are all over the place

I need the arrows to look more like this:


maybe if I break the data down by days, it will clean it up

1 Like

update: that did not work. Any tips on making my plot less noisy?

what didnt work ? you provided images not code.

I am trying to use the plotSticks function but when I run this code, the vectors do not appear.

wind<-read.csv("wind.csv")

u<-wind[["u"]]
v<-wind[["v"]]
p<-wind[["p"]]
xt<-wind[["dt"]]
dt<- as.POSIXct(xt, format="%m/%d/%y %H:%M %p",tz="")
oce.plot.ts(dt,p)
plotSticks(dt,3.0,u,v,yscale = 200, add = TRUE)
plotSticks(dt,3.0,u,v,yscale = 500, add = TRUE)
There were 12 warnings (use warnings() to see them)

Hi, follow this steps:


you have your date in Julian but you need it something like this
Screenshot_658
for that you have to run this lines
df$date <-as.Date(df$dt, origin=as.Date("1960-01-01"))
df$time <- as.POSIXct(df$date, tz='UTC')

now, for the plot

library(oce)
tt <- df$time
plotSticks(tt, 0, df$u, df$v, yscale=10, ylab='', yaxt='n', length=0)

for "clean the arrows"

library(signal)
bw <- butter(1, 0.1) # lowpass with normalized cutoff of 0.1
uf <- filtfilt(bw, df$u)
vf <- filtfilt(bw, df$v)
plotSticks(tt, 0, uf, vf, yscale=10, xlab='', ylab='', yaxt='n', length=0)

I'm a new user so I can't upload many photos, sorry if my english is not good.
Just follow the info in the link and good luck.