我有这个数据集
structure(list(collegeAbb = c("Agriculture", "Agriculture", "Agriculture",
"Art", "Art", "Art", "Business", "Business", "Business", "Coast",
"Coast", "Coast", "Engineering", "Engineering", "Engineering",
"Human Science", "Human Science", "Human Science", "Humanities",
"Humanities", "Humanities", "Law", "MassComm", "MassComm", "MassComm",
"Music", "Music", "Music", "Not provided", "Not provided", "Not provided",
"Science", "Science", "Science", "Veterinary", "Veterinary",
"Veterinary"), degreeLevel = structure(c(1L, 2L, 3L, 1L, 2L,
3L, 1L, 2L, 3L, 1L, 2L, 3L, 1L, 2L, 3L, 1L, 2L, 3L, 1L, 2L, 3L,
3L, 1L, 2L, 3L, 1L, 2L, 3L, 1L, 2L, 3L, 1L, 2L, 3L, 1L, 2L, 3L
), .Label = c("Bachelor", "Master", "PhD"), class = "factor"),
count = c(775, 151, 83, 439, 93, 2, 2309, 857, 37, 45, 49,
22, 2039, 294, 154, 1845, 876, 116, 3021, 339, 144, 3, 659,
60, 12, 173, 117, 52, 8, 3, 5, 1346, 176, 167, 5, 9, 201)), .Names = c("collegeAbb",
"degreeLevel", "count"), class = c("tbl_df", "tbl", "data.frame"
), row.names = c(NA, -37L))
我试图以这种方式将变量degreeLevel
映射到fill属性:
dd %>%
ggvis(x=~collegeAbb, y=~count) %>%
layer_bars( fill:= ~ factor(degreeLevel))
但是,因为并非collegeAbb
中的所有变量,所以当我设置fill:=~factor(degreeLevel)
时,我收到错误消息:
Warning message:
In bind_rows_(x, .id) : Unequal factor levels: coercing to character
如何告诉ggvis将缺失因子值的值视为零?