r - 在 R 中创建具有多个组的箱线图
问题描述
我使用 ggplot 为我拥有的一组数据制作了一个包含多个组的条形图(使用 7 点李克特量表测量脉冲宽度和频率的紧迫性、烦恼、效价和唤醒水平)。分组基于我的数据集中的变量,这是我需要的
我使用的代码如下:
breaks = c(1,2,3,4,5,6,7)
labels = as.character(breaks)
breaks2 = c(10, 30, 50, 70, 90, 110)
labels2 = as.character(breaks2)
BarChart_Freq_Dvs = ggplot(AllResults, aes(Frequency, value, group = variable,
shape = variable, linetype=variable, fill = variable))
BarChart_Freq_Dvs +
stat_summary(fun.y = mean, geom = "bar", width = 9, position = position_dodge(width = 11))+
stat_summary(fun.data = mean_cl_normal, geom = "errorbar", width = 7, position = position_dodge(width
= 11))+
scale_y_continuous(name = "likert scale",
limits = c(1,7), breaks = breaks, labels = labels, oob = rescale_none)+
scale_x_continuous(name = "Frequency",
limits = c(10,110), breaks = breaks2, labels = labels2, oob = rescale_none, expand
= c(0.06,0))+
theme_classic()+
theme(panel.background = element_rect(fill = NA),
panel.grid.major.y = element_line(colour = "grey50"),
panel.ontop = TRUE)
然后我决定用箱形图替换条形图并写道:
Box_Plot = ggplot(AllResults, aes(Frequency, value, group = variable,
shape = variable, linetype=variable, fill = variable))
Box_Plot +
geom_boxplot() +
scale_y_continuous(name = "likert scale", limits = c(1,7), breaks = breaks, labels = labels, oob =
rescale_none)+
scale_x_continuous(name = "Frequency",
limits = c(10,110), breaks = breaks2, labels = labels2, oob = rescale_none,
expand = c(0.06,0))+
theme_classic()+
theme(panel.background = element_rect(fill = NA),
panel.grid.major.y = element_line(colour = "grey50"),
panel.ontop = TRUE)
但我得到了下面的图表,它确实有意义
我在互联网上搜索了一个修复程序,我发现的所有代码都和我写的几乎一样。我不知道我的代码问题出在哪里。
样本 :
PW Frequency variable value
High 110 urgency 3
Middle 10 urgency 2
Low 70 urgency 2
High 30 urgency 5
Middle 50 urgency 3
Low 70 annoyance 5
Middle 50 annoyance 4
High 90 annoyance 7
Middle 90 annoyance 5
High 110 annoyance 7
High 10 annoyance 2
High 50 valence 3
Middle 10 valence 4
Low 50 valence 4
Middle 50 valence 4
Low 30 valence 4
Middle 30 valence 4
High 90 arousal 4
Middle 110 arousal 3
High 70 arousal 3
Middle 70 arousal 2
Middle 90 arousal 2
Low 10 arousal 1
解决方案
推荐阅读
- fortran - 错误:Fortran 代码上的不可分类语句(解码)
- wpf - 我在设置树视图根节点的背景颜色时遇到问题。
- algorithm - 伪随机算法
- android - 实现 Google Calendar V3 API 无需用户登录到 Gmail 帐户
- python - Pandas - 在多列中查找和迭代具有匹配值的行并在另一列中相乘
- docker - 无法从主机访问在 Docker 自定义桥接网络中发布的端口
- python - 设置seaborn facet grid的标签位置
- c++ - 我的碰撞检测中的奇怪行为
- reactjs - React 中具有“变体”的组件 - 条件渲染
- shell - 在 shell 脚本中迭代地从列中过滤出值