で次のように試すことができます。が、あなたのデータサイズが小さいので、プロットは非常に派手ではありません。別のライブラリopenair
で
library(circular)
df <- read.table(text='Dir N
1: 360 56564
2: 0 NA
3: 180 149374
4: 210 82219
5: 240 23315
6: 300 11436
7: 330 30648
8: 30 32198
9: 60 15266
10: 90 14596
11: 120 26267
12: 150 81782
13: 270 10100', header=TRUE)
rownames(df) <- NULL
names(df) <- c('dir', 'mag')
df$dir <- circular(as.numeric(df$dir), units='degrees')
df$mag <- df$mag/10000 # scale magnitude
windrose(df, breaks=circular(seq(0, 2 * pi, by = pi/4)), increment=5)
それは次のようになります。
library(openair)
df <- read.table(text='Dir N
1: 360 56564
2: 0 NA
3: 180 149374
4: 210 82219
5: 240 23315
6: 300 11436
7: 330 30648
8: 30 32198
9: 60 15266
10: 90 14596
11: 120 26267
12: 150 81782
13: 270 10100', header=TRUE)
names(df) <- c('wd', 'ws')
df$ws <- df$ws/10000 # scale speed
windRose(df, angle=45)
ggplot2
の極座標プロットは異なって見えます(geom_bar
を極座標座標)
library(ggplot2)
ggplot(df, aes(x=dir, y=mag)) + geom_bar(stat='identity') + coord_polar()
例えばpolygon
の代わりに使用し、私は、あなたが常に実装の効率を向上させることができ、単にアイデアのために、実装は非常に効率的ではない(ゼロからbase R
にしようとしたいくつかの実装弧を埋めるためにsegments
)、我々はggplot
に1を模倣するbase R
で同様の実装を使用することができます。
add.filled.arc <- function(center.x, center.y, radius, angle.start, angle.end, col='black') {
theta <- seq(angle.start, angle.end, .0001)
segments(0, 0, radius*cos(theta), radius*sin(theta), col)
segments(0, 0, cos(angle.start), sin(angle.start), col='gray')
segments(0, 0, cos(angle.end), sin(angle.end), col='gray')
}
plot.coord.polar <- function(df) {
df <- df[complete.cases(df),]
df <- df[order(df[,1]),]
df[,1] <- df[,1]*(pi/180) # convert dir to radian
df[,2] <- df[,2]/max(df[,2]) # normalize magnitude within [0-1]
plot(-1:1, -1:1, type= 'n', xlab='', ylab='', xaxt='n', yaxt='n')
sapply(1:(nrow(df)-1), function(i) add.filled.arc(0, 0, df[i,2], df[i,1], df[i+1,1], rainbow(nrow(df))[i]))
theta <- seq(0, 2*pi, 0.0001)
lines(cos(theta), sin(theta), col='gray')
}
df <- read.table(text='Dir N
1: 360 56564
2: 0 NA
3: 180 149374
4: 210 82219
5: 240 23315
6: 300 11436
7: 330 30648
8: 30 32198
9: 60 15266
10: 90 14596
11: 120 26267
12: 150 81782
13: 270 10100', header=TRUE)
plot.coord.polar(df)
ヒストグラムとしてどのプロット変数をプロットしたいですか?私はNを推測していますか? –
はい、N. Dirはx軸のようになります。 – mclzc