我有一个名为“ dt”的数据框(其中包含100个人,但将其缩减为8),并且必须在5个时间间隔内绘制薪金统计图(所以假设= 20,000)
ID Salary Bonus
--------------------------
1: 1 100000 57
2: 2 86000 66
3: 3 17000 12
4: 6 50500 37
5: 9 35000 26
6: 10 45000 21
7: 11 95000 54
8: 12 100000 58
我如何用barplot()完成它?这是我尝试做的:
barplot(cut(dt $ Salary,c(seq(1,max(dt $ Salary),by = 20000))))
但它说“高度”必须是向量或矩阵。
我们可以cut
用breaks
5来表示“薪水”,用来获得频率计数table
并用来绘制barplot
barplot(table(cut(df1$Salary, breaks = 5)))
或指定min
,并max
在seq
得到一个序列by
20000
barplot(table(cut(df1$Salary,
breaks = seq(min(df1$Salary)- 100, max(df1$Salary) + 100, by = 20000))))
df1 <- structure(list(ID = c(1L, 2L, 3L, 6L, 9L, 10L, 11L, 12L), Salary = c(100000L,
86000L, 17000L, 50500L, 35000L, 45000L, 95000L, 100000L), Bonus = c(57L,
66L, 12L, 37L, 26L, 21L, 54L, 58L)), class = "data.frame", row.names = c("1:",
"2:", "3:", "4:", "5:", "6:", "7:", "8:"))
本文收集自互联网,转载请注明来源。
如有侵权,请联系 [email protected] 删除。
我来说两句