0

I would appreciate your help.

I am using the function windRose of the openair package for R to plot current speed and direction. Since I am using the circular function in the windrose function it does not present a color scale bar for wind speed. It does show one without using the circular function.

my data is arranged in 2 columns, 1st the speed and 2nd the direction (0-360). this is my code:

windrose(x=circular(data$Direction,template='geographics',units = "degrees"), y=data$Speed, increment = 25,fill.col=rainbow(12),label.freq=T,xlim=c(-2.1, 2.1), ylim=c(-2.1, 2.1))

can anyone explain how to get the color legend? thank you for your help

Terru_theTerror
  • 4,918
  • 2
  • 20
  • 39
  • Welcome to Stack Overflow and thanks for your question. Here is quick [Tour](https://stackoverflow.com/tour) of the important things to know. It is also recommended to create a reproducible example when posting a question. Check out [How to make a great R reproducible example](https://stackoverflow.com/questions/5963269/how-to-make-a-great-r-reproducible-example) – Emer Feb 20 '18 at 10:47

1 Answers1

0

First, let's use some available data to all of us in order to reproduce the code. In this case, they are wind speed and direction from openair package, quite similar to fluid current speed and direction you are using

library(openair)
library(circular)

# Using "mydata" dataset from openair package as an example
data <- data.frame("Speed" = mydata$ws, "Direction"=mydata$wd)

windrose(x = circular(data$Direction, template = 'geographics', units = "degrees"), 
         y = data$Speed, 
         increment = 25,
         fill.col = rainbow(12),
         label.freq = T, 
         xlim = c(-2.1, 2.1), 
         ylim = c(-2.1, 2.1))

Not sure which openair package version are you using (mine is 2.1.5) but your function call does not match the signature in the help (the parameter names are different). You can check them out in the help using:

help(windRose) 

Having said that, I would also suggest to split your code in 2 steps:

1) Create the dataset. windRose function looks for variable names ws (Wind Speed [m/s]) and wd (Wind Direction [deg from North]), you can use them. Make sure the data frame contains the correct values and units. Visualize by using head(data2) or str(data2). Note that data here is your own dataset.

data2 <- data.frame("ws" = as.numeric(circular(data$Direction, template = 'geographics', units = "degrees")), 
                    "wd" = data$Direction)

2) Plot the data frame with ws and wd variable names.

data <- data.frame("Speed" = mydata$ws, "Direction"=mydata$wd)
data2 <- data.frame("ws"=data$Speed, "wd"=data$Direction)
head(data2)
    ws  wd
1 0.60 280
2 2.16 230
3 2.76 190
4 2.16 170
5 2.40 180
6 3.00 190
windRose(data2)

enter image description here

Emer
  • 3,734
  • 2
  • 33
  • 47