根据某些值的观察次数在 R 中绘制箱线图

Boxploting in R from number of observations for some value

我需要从某个日期开始在 R 中绘制箱线图,该日期以表格文件 (tsv) 的形式出现,其中包含某个具体值在样本中出现的次数。 我尝试使用以下代码:

freqs <- read.table('tabular_file_with_observations.tsv')
sample <- rep(freqs$V1,freqs$V2)
boxplot(sample)

tabular_file_with_observations.tsv有以下内容:

0   3040
1   2104
2   1358
3   2153
4   1172
5   741
...

代表的是值'0'在样本中出现了3040次,'1'出现了2104次,等等

R 命令 rep 'unfolds' 计数到样本中,但它占用大量内存,并且在尝试绘制箱线图之前 R 崩溃。 我试图在网上搜索,希望能找到一些东西,但我不是 R 的专业人士,所以我需要帮助。 提前致谢

轻松 ggplot2:

data <- read.table(text="
0   3040
1   2104
2   1358
3   2153
4   1172
5   741")

library(ggplot2)
ggplot(data, aes(x=0, y=V1, weight=V2)) + geom_boxplot()

x=0假设你只有一组;如果您有多个组,请将其替换为分组变量。