I have a dataset which includes BSP, TWD, TWS, as well as label for different crew watches. With this I would like to create a wind rose graph that shows the boat speed and wind direction by day or each watch. I found some direction at 17266788 and followed the function created by Andy Clifton. I was able to replicate the function and results using the same wind data and then apply the function without any facet to my sail log data. When applying the facet portion to the wind data I got the same results reflected in the answer posted by Andy. However, when I went to try and add a facet by either the day (an integer formatted from a UTC attribute) or watch label I get the error <At least one layer must contain all faceting variables: utc_int.factor
>
Here is a subset data.frame
df_0 <- data.frame(UTC = c(45117.171132,45117.17371,45117.358592,45117.360963,45117.376829,45117.393799,45117.401636,45117.465761,45117.483411,45117.488394), BSP = c(7.343,8.033,6.816,8.197,11.814,8.724,6.997,10.269,10.614,10.796), TWD = c(75.5,55.5,37.6,39.9,27.7,136.1,122,33.7,46.8,45.1), TWS = c(16.41,14.45,16.5,18.68,17.33,17.79,17.93,17.97,22.36,18.43), watch_lbl_adj = c("K","K","A","A","B","B","B","C","C","C"))
After which I ran the following:
df_0.wrose.1 <- plot.windrose(data = df_0, spd = df_0$BSP, dir =df_0$TWD)
df_0 <- df_0 %>% mutate(watch_asfactor = factor(watch_lbl_adj))
df_0.wrose.1 <- plot.windrose(data = df_0, spd = df_0$BSP, dir = df_0$TWD)
df_0.wrose.2 <- df_0.wrose.1 + facet_wrap(~watch_asfactor, ncol = 2)
Running:
df_0.wrose.1 <- plot.windrose(data = df_0, spd = df_0$BSP, dir = df_0$TWD)
produced a windrose plot similar to what Andy got with his function. After running
df_0.wrose.1 + facet_wrap(~watch_asfactor, ncol = 2)
I received the error. I believe I'm doing the same sequence of steps Andy showed after adding the Year & Month although I'm not specifying the levels when creating a separate factor. I found 6992592 which suggests some elements when passed to ggplot are dropped but I don't get the error when I follow Andy's answer exactly. I also looked at 50528747 and the answer maybe in the answers provided but it isn't making sense to me; a newbie with R.