如何通过R中的x值缩放直方图上的y轴? [英] How do I scale the y-axis on a histogram by the x values in R?
问题描述
我有一些表示粒子大小的数据.我想将每个合并大小的粒子的频率绘制为直方图,但要缩放频率但要调整粒子的大小(因此它表示该大小的总质量.)
I have some data which represents a sizes of particles. I want to plot the frequency of each binned-size of particles as a histogram, but scale the frequency but the size of the particle (so it represents total mass at that size.)
我可以很好地绘制直方图,但是我不确定如何通过每个bin的X值缩放Y轴.
I can plot a histogram fine, but I am unsure how to scale the Y-axis by the X-value of each bin.
例如如果我在40-60格中有10个粒子,我希望Y轴值为10 * 50 = 500.
e.g. if I have 10 particles in the 40-60 bin, I want the Y-axis value to be 10*50=500.
推荐答案
您最好使用barplot,以便通过垃圾箱的面积表示总质量(即,高度表示计数,宽度表示质量):>
You would better use barplot in order to represent the total mass by the area of the bins (i.e. height gives the count, width gives the mass):
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因子:
If your particle sizes are all different, you should first cut the range into appropriate number of intervals in order to create part.type factor:
part <- rchisq(1000, 10)
part.type <- cut(part, 4)
count <- table(part.type)
barplot(count, width = size)
如果感兴趣的数量仅是总质量.然后,适当的绘图为点图.与大量尺寸的条形图相比,它也更加清晰:
If the quantity of interest is only total mass. Then, the appropriate plot is the dotchart. It is also much clearer comparing to the bar plot for a large number of sizes:
part <- rchisq(1000, 10)
part.type <- cut(part, 20)
count <- table(part.type)
dotchart(count)
用垃圾箱表示总质量会产生误导,因为垃圾箱的面积没有意义.
Representing the total mass with bins would be misleading because the area of the bins is meaningless.
这篇关于如何通过R中的x值缩放直方图上的y轴?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!