R中一列数据的绘图频率分布 [英] Plot Frequency Distribution of One-Column Data in R
问题描述
我有一个系列的值(即,一列数据),我想创建一个图,其x轴上的数据值范围以及每个值出现在数据集上的频率y轴。
I have a single series of values (i.e. one column of data), and I would like to create a plot with the range of data values on the x-axis and the frequency that each value appears in the data set on the y-axis.
我想要的非常接近内核密度图:
# Kernel Density Plot
d <- density(mtcars$mpg) # returns the density data
plot(d) # plots the results
但是,我想在y轴上输入频率(相对于密度)。
However, I would like frequency (as opposed to density) on the y-axis.
具体来说,我在工作具有网络度分布,并且想要具有开放圆形点的双对数刻度,即此图片。
Specifically, I'm working with network degree distributions, and would like a double-log scale with open, circular points, i.e. this image.
我已经研究了相关的资源和问题,但是没有找到我想要的东西:
I've done research into related resources and questions, but haven't found what I wanted:
R的绘图分布接近我想要的内容,但不是恰恰。我想用直方图示例中定义的计数替换其密度曲线示例中的y轴。
Cookbook for R's Plotting distributions is close to what I want, but not precisely. I'd like to replace the y-axis in its density curve example with "count" as it is defined in the histogram examples.
R中的ecdf()
函数(即这个问题)可能就是我想要的,但是我想要观察到的频率,而不是y轴上0到1之间的归一化值。
The ecdf()
function in R (i.e. this question) may be what I want, but I'd like the observed frequency, and not a normalized value between 0 and 1, on the y-axis.
此问题与频率分布有关,但我想指出
This question is related to frequency distributions, but I'd like points, not bars.
编辑:
数据是标准幂律分布,即
The data is a standard power-law distribution, i.e.
dat <- c(rep(1, 1000), rep(10, 100), rep(100, 10), 100)
推荐答案
如果您有用于观察的离散值并且想要进行一个在对数刻度上具有点的图,然后
If you have discrete values for observations and want to make a plot with points on the log scale, then
dat <- c(rep(1, 1000), rep(10, 100), rep(100, 10), 100)
dd<-aggregate(rep.int(1, length(dat))~dat, FUN=sum)
names(dd)<-c("val","freq")
plot(freq~val, dd, log="xy")
可能就是您所追求的。
这篇关于R中一列数据的绘图频率分布的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!