我正在尝试创建数据的直方图。 我的数据框看起来像这样
x counts
4 78
5 45
... ...
其中 x 是我想要绘制的变量,counts 是观测值的数量。如果我执行 hist(x) 情节会产生误导,因为我没有考虑计数。我也试过:
hist(do.call("c", (mapply(rep, df$x, df$count))))
不幸的是,这不起作用,因为生成的向量太大了
sum(df$ount)
[1] 7943571126
还有其他方法可以尝试吗?
谢谢
最佳答案
解决方案是 @Rui Barradas 建议的条形图。我使用 ggplot
来绘制数据。
library(ggplot2)
x <- c(4, 5, 6, 7, 8, 9, 10)
counts <- c(78, 45, 50, 12, 30, 50)
df <- data.frame(x=x, counts=counts)
plt <- ggplot(df) + geom_bar(aes(x=x, y=counts), stat="identity")
print(plt)
关于r - 带计数 R 的直方图,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/51762720/