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?
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.
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")
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
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:
t<-convertToDateTime(xt, origin = "1955-05-07")
plotSticks(t,2061, u, v, yscale=25, add = TRUE)
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
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.
dt<- as.POSIXct(xt, format="%m/%d/%y %H:%M %p",tz="")
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
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.
This topic was automatically closed 21 days after the last reply. New replies are no longer allowed.
If you have a query related to it or one of the replies, start a new topic and refer back with a link.
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
this is some of the data I am trying to use
the code and error message I am getting is this:
set working directory
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