我正在尝试根据每个基本方向的频率创建一个图。我遵循了这个优秀资源的说明,但是当我尝试将垃圾箱置于中间时,我遇到了一个主要问题(例如,在“北”垃圾箱内从 NNW 到 N 到 NNE 的观察)。在最初的示例中,没有发现极端值,因此它没有显示为问题。
library(gcookbook) # Load gcookbook for the wind data set
wind
w287<-c(0, 3.5, 9, 10, 90, 5, 358)
w288<-c(0, 3.5, 9, 10, 90, 5, 357)
w289<-c(0, 3.5, 9, 10, 90, 5, 1)
w290<-c(0, 3.5, 9, 10, 90, 5, 2)
wind2<-rbind(wind, w287, w288, w289, w290,w287, w288, w289, w290,w287, w288, w289, w290,w287, w288, w289, w290,w287, w288, w289, w290,w287, w288, w289, w290)
wind2[is.na(wind2$SpeedCat),]$SpeedCat<-">20"
#initial plot without rotation
a<-ggplot(wind2, aes(x = DirCat)) +
geom_histogram(binwidth = 90, boundary = 0) +
coord_polar() +
labs(title="Bins visible : no rotation")+
scale_x_continuous(limits = c(0,360))
#plot with rotation in which the values from bin#1 are lost
b<-ggplot(wind2, aes(x = DirCat)) +
geom_histogram(binwidth = 90, boundary = -45) +
coord_polar() +
labs(title="Bin not visible: rotation")+
scale_x_continuous(limits = c(0,360))
c<-ggplot(wind2, aes(x = DirCat)) +
geom_histogram(binwidth = 90, boundary = -45) +
coord_polar() +
labs(title="Bin visible: rotation + scale increased")+
scale_x_continuous(limits = c(-45,405))
grid.arrange(a, b, c, ncol=3)