小编GTK*_*GTK的帖子

如何使用ggplot2和stat_bin制作包含没有观察值的数字级别的条形图

我有数据作为有序因子,水平1,2,3,4,5.(这是李克特量表数据.)我想用ggplot创建一个计数条形图,但这必须包括所有级别,甚至是零计数的级别.这是一个示例数据帧,其等级为零,计数为零.

library(ggplot2)

foo <- structure(list(feed.n.1.50..3. = structure(c(4L, 4L, 4L, 4L, 
4L, 5L, 5L, 4L, 1L, 1L,1L, 1L, 4L, 4L, 4L, 4L, 4L, 4L, 4L, 4L, 
4L, 4L, 4L, 4L, 4L, 5L, 5L, 4L, 5L, 4L, 4L, 4L, 4L, 4L, 4L, 4L, 
5L, 3L, 4L, 4L, 3L, 4L, 4L, 3L, 4L, 5L, 4L, 4L, 4L, 4L), .Label = c("1", 
"2", "3", "4", "5"), class = c("ordered", "factor"))), .Names = "answers", row.names = c(NA, 
-50L), class = "data.frame")

table(foo) # satisfy myself …
Run Code Online (Sandbox Code Playgroud)

r ggplot2

3
推荐指数
1
解决办法
294
查看次数

标签 统计

ggplot2 ×1

r ×1