我试图在一个条形图中使用多个列名作为x轴。因此,每个列名称将是“因子”,它包含的数据是该数量的计数。
我尝试过迭代:
ggplot(aes( x = names, y = count)) + geom_bar()
我尝试连接我要用aes(c(col1, col2))
显示的x值但是美学长度不匹配且不起作用。
library(dplyr)
library(ggplot2)
head(dat)
Sample Week Response_1 Response_2 Response_3 Response_4 Vaccine_Type
1 1 1 300 0 2000 100 1
2 2 1 305 0 320 15 1
3 3 1 310 0 400 35 1
4 4 1 400 1 410 35 1
5 5 1 405 0 180 35 2
6 6 1 410 2 800 75 2
dat %>%
group_by(Week) %>%
ggplot(aes(c(Response_1, Response_2, Response_3, Response_4)) +
geom_boxplot() +
facet_grid(.~Week)
dat %>%
group_by(Week) %>%
ggplot(aes(Response_1, Response_2, Response_3, Response_4)) +
geom_boxplot() +
facet_grid(.~Week)
> Error: Aesthetics must be either length 1 or the same as the data
> (24): x
这两个都失败了(基于aes长度错误代码预期的那种),但希望你知道我的目标并且可以提供帮助。
目标是拥有4个独立的小组,每个小组都有自己的箱形图(每个响应都有1个)。并且还让他们在一周之内受到影响。