二进制变量的频率图

时间:2017-04-16 15:16:49

标签: r binary boxplot

我正在尝试为二进制变量创建一个简单的boxplot。我正在处理这些数据:

structure(list(status = c(1L, 1L, 1L, 0L, 0L, 1L, 0L, 1L, 0L, 
0L, 0L, 0L, 0L, 0L, 1L, 1L, 1L, 0L, 0L, 1L), length = c(1520L, 
1250L, 870L, 720L, 820L, 770L, 50L, 570L, 580L, 480L, 470L, 450L, 
435L, 275L, 256L, 230L, 330L, 330L, 300L, 180L), mass = c(9600, 
5000, 3360, 2517, 3170, 4390, 1930, 1020, 910, 590, 539, 940, 
684, 230, 162, 170, 501, 439, 386, 95), range = c(1.21, 0.56, 
0.07, 1.1, 3.45, 2.96, 0.01, 9.01, 7.9, 4.33, 1.04, 2.17, 4.81, 
0.31, 0.24, 0.77, 2.23, 0.22, 2.4, 0.69), migr = c(1L, 1L, 1L, 
3L, 3L, 2L, 1L, 2L, 3L, 3L, 3L, 3L, 3L, 1L, 1L, 1L, 1L, 1L, 1L, 
2L), insect = c(12L, 0L, 0L, 12L, 0L, 0L, 0L, 6L, 6L, 0L, 12L, 
12L, 12L, 3L, 3L, 3L, 3L, 3L, 3L, 12L), diet = c(2L, 1L, 1L, 
2L, 1L, 1L, 1L, 2L, 2L, 1L, 2L, 2L, 2L, 1L, 1L, 1L, 1L, 2L, 1L, 
2L)), .Names = c("status", "length", "mass", "range", "migr", 
"insect", "diet"), row.names = c(1L, 2L, 3L, 4L, 5L, 6L, 7L, 
9L, 10L, 11L, 12L, 13L, 14L, 15L, 16L, 17L, 18L, 19L, 20L, 22L
), class = "data.frame")

我使用boxplot函数进行了尝试,但只获得了一个而不是2个。

boxplot(birds$status)

我也尝试过ggplot函数:

ggplot(birds$status) + geom_boxplot()
ggplot() + aes(birds) + geom_boxplot()
ggplot(birds, aes(x= status, group=status)) + geom_boxplot()

如何获得一个有两个方框的箱线图,0 =缺席,1 =存在?

1 个答案:

答案 0 :(得分:1)

根据您的上述评论,您要查找的是barplottable来计算频率:

barplot(table(birds$status))

enter image description here