粒子のサイズを表すデータがあります。各ビニングサイズの粒子の頻度をヒストグラムとしてプロットしたいのですが、頻度をスケーリングしますが、粒子のサイズをスケーリングします(したがって、そのサイズでの総質量を表します)。
ヒストグラムをうまくプロットできますが、各ビンの X 値で Y 軸をスケーリングする方法がわかりません。
たとえば、40-60 ビンに 10 個のパーティクルがある場合、Y 軸の値を 10*50=500 にしたいと考えています。
各ビンの中間点をスケーリング係数として本当に使用したい場合:
d<-rgamma(100,5,1.5) # sample
z<-hist(d,plot=FALSE) # make histogram, i.e., divide into bins and count up
co<-z$counts # original counts of each bin
z$counts<-z$counts*z$mids # scaled by mids of the bin
plot(z, xlim=c(0,10),ylim=c(0,max(z$counts))) # plot scaled histogram
par(new=T)
plot(z$mids,co,col=2, xlim=c(0,10),ylim=c(0,max(z$counts))) # overplot original counts
代わりに、各サンプル ポイントの実際の値をスケーリング ファクターとして使用する場合は、次のようにします。
d<-rgamma(100,5,1.5)
z<-hist(d,plot=FALSE)
co<-z$counts # original counts of each bin
z$counts<-aggregate(d,list(cut(d,z$breaks)),sum)$x # sum up the value of data in each bin
plot(z, xlim=c(0,10),ylim=c(0,max(z$counts))) # plot scaled histogram
par(new=T)
plot(z$mids,co,col=2, xlim=c(0,10),ylim=c(0,max(z$counts))) # overplot original counts
総質量をビンの面積で表すには、barplot を使用することをお勧めします (つまり、高さはカウント、幅は質量を示します)。
sizes <- 3:10 #your sizes
part.type <- sample(sizes, 1000, replace = T) #your particle sizes
count <- table(part.type)
barplot(count, width = size)
粒子サイズがすべて異なる場合は、part.type ファクターを作成するために、まず範囲を適切な数の間隔に分割する必要があります。
part <- rchisq(1000, 10)
part.type <- cut(part, 4)
count <- table(part.type)
barplot(count, width = size)
対象量が全質量のみの場合。次に、適切なプロットはドットチャートです。また、多数のサイズの棒グラフと比較すると、はるかに明確です。
part <- rchisq(1000, 10)
part.type <- cut(part, 20)
count <- table(part.type)
dotchart(count)
ビンの面積は無意味であるため、ビンで総質量を表すことは誤解を招く可能性があります。
軸を非表示にして、必要に応じて再プロットするだけです。
# Generate some dummy data
datapoints <- runif(10000, 0, 100)
par (mfrow = c(2,2))
# We will plot 4 histograms, with different bin size
binsize <- c(1, 5, 10, 20)
for (bs in binsize)
{
# Plot the histogram. Hide the axes by setting axes=FALSE
h <- hist(datapoints, seq(0, 100, bs), col="black", axes=FALSE,
xlab="", ylab="", main=paste("Bin size: ", bs))
# Plot the x axis without modifying it
axis(1)
# This will NOT plot the axis (lty=0, labels=FALSE), but it will return the tick values
yax <- axis(2, lty=0, labels=FALSE)
# Plot the axis by appropriately scaling the tick values
axis(2, at=yax, labels=yax/bs)
}