我喜欢在绘图时生成自己的网格线,因此我可以控制刻度线等等.我正在使用'hist'绘图程序来解决这个问题.
hist(WindSpeed, breaks=c(0:31), freq=TRUE, col="blue", xaxt="n", yaxt="n", xlab="Wind Speed (m/s)",main="Foo", cex.main=1.5, cex.axis=1, cex.lab=1, tck=1, font.lab=2)
axis(1, tck=1, ,col.ticks="light gray")
axis(1, tck=-0.015, col.ticks="black")
axis(2, tck=1, col.ticks="light gray", lwd.ticks="1")
axis(2, tck=-0.015)
minor.tick(nx=5, ny=2, tick.ratio=0.5)
box()
Run Code Online (Sandbox Code Playgroud)
情节:

然后我就可以使用'lines'或'points'命令在其他类型的图上重新绘制数据,但是直方图并不那么容易.
任何帮助都会很棒.
我在下面添加了我的代码并根据John的回复图像...
我在下面添加了我的代码并根据John的回复图像...
hist(WindSpeed, breaks=30, freq=TRUE, col="blue", xaxt="n", yaxt="n", xlab="Wind Speed (m/s)",main="Foo", cex.main=1.5, cex.axis=1, cex.lab=1, font.lab=2)
axis(1, tck=1, col.ticks="light gray")
axis(1, tck=-0.015, col.ticks="black")
axis(2, tck=1, col.ticks="light gray", lwd.ticks="1")
axis(2, tck=-0.015)
minor.tick(nx=5, ny=2, tick.ratio=0.5)
box()
hist(WindSpeed, add=TRUE, breaks=30, freq=TRUE, col="blue", xaxt="n", yaxt="n", xlab="Wind Speed (m/s)", main="Foo", …Run Code Online (Sandbox Code Playgroud) 由于罗盘标题范围为0-360度,平均标量风向数据会产生不准确的值,所以我已经将我的列表从幅度和风向角度转换为u和v分量.
为了取消适当的风向,为了平均目的,我需要为以下三种情况开发某种应用,ifelse功能:
V > 0...((180 / pi) * atan((Ucomp/Vcomp)) + 180)
U and V < 0...((180 / pi) * atan((Ucomp/Vcomp)) + 0)
U > 0 and V < 0...((180 / pi) * atan((Ucomp/Vcomp)) + 360)
Run Code Online (Sandbox Code Playgroud)
在我想要分析的数据集中,Ucomp大于0且Vcomp小于零,但毫无疑问会出现所有3都会出现的情况,所以我需要一个函数来解析并迭代计算并应用正确的每个时间步的公式.我之前没有使用lapply或函数,所以我玩它们并没有奏效.
我在下面提供了一些数据样本......
DateTime Wind.Spd Wind.Direction Air.Density Temp.C GEP.GE16XLE GCF.GE16XLE Ucomp Vcomp
1 1981 7.662370 248.3395 0.9148207 11.28967 597.7513 37.35946 5.253453 -0.7404972
2 1982 8.199412 251.6763 0.9172176 10.12751 678.8595 42.42872 5.867979 -0.6191475
3 1983 8.188782 251.7889 0.9162767 10.30619 667.9461 41.74663 5.777208 -1.0473982
4 1984 7.942632 246.7908 …Run Code Online (Sandbox Code Playgroud) 下面的列表是使用以下代码段在时间序列中与每个月对应的数据总和:
aggregate(data, by=list(Year=format(DateTime, "%Y"), Month=format(DateTime, "%m")), sum, na.rm=TRUE)
Year Month x
1 1981 01 62426.43
2 1982 01 70328.87
3 1983 01 67516.34
4 1984 01 64454.00
5 1985 01 78801.46
6 1986 01 73865.18
7 1987 01 64224.96
8 1988 01 72362.39
9 1981 02 74835.16
10 1982 02 75275.58
11 1983 02 67457.39
12 1984 02 64981.99
13 1985 02 56490.10
14 1986 02 62759.89
15 1987 02 65144.44
16 1988 02 67704.67
Run Code Online (Sandbox Code Playgroud)
这部分很容易......但是我试图获得每个月的所有月度总和的平均值(即每个月的平均值)如果我执行以下操作:
aggregate(data, by=list(Month=format(DateTime, "%m")), sum, …Run Code Online (Sandbox Code Playgroud)