r - 尝试对数据进行分组并绘制 ggplot 直方图时出现问题
问题描述
我有一个 csv 文件,其中包含这三列数据条目:
before after Style
14 20 group
2 0 alone
17 17 alone
4 2 group
6 3 group
我设法绘制了一个比较前后值的 ggplot 直方图。
library(ggplot2)
library(reshape2)
responses = read.csv("dataframe.csv")
responses$exercise_style <- as.factor(responses$exercise_style)
responses$Exercise_before = as.numeric(as.character(responses$Exercise_before))
responses$Exercise_after = as.numeric(as.character(responses$Exercise_after))
before = responses$Exercise_before
after = responses$Exercise_after
Style = responses$exercise_style
frame1 = data.frame(before,after,hours)
frame2 = melt(frame1,id.vars = 'hours')
plotting = ggplot(frame2,aes(x = hours, y = value, fill = variable))
Bars = geom_bar(stat="identity",position="dodge")
plotting + Bars
解决方案
您正在尝试表示 3 维数据。我能想到的唯一方法是,因为您只有 2 种样式,您可以为不同的样式使用不同的颜色组。例如,单独可以使用蓝色和青色,组可以使用红色和黄色。只是一个意见
推荐阅读
- ffmpeg - 如何在背景图像上叠加视频?
- ansible - 迭代 Ansible 调试输出
- excel - 第一次迭代后循环文件夹中的所有文件失败
- docker - 使用 docker 构建时 Azure DevOps 私有 nuget 存储库未经授权
- webassembly - 为什么 0x83 0x00 格式良好的 3 编码为 Wasm 中的 u8?
- python - Conda 环境:打印已安装软件包的许可证
- python - 如何不打印 cmd 输出?
- javascript - 当我使用画布和 requestAnimationFrame 为图像数组设置动画时的位置问题
- vim - 删除行中的特定字符
- bash - 如何在 shell 脚本中添加进度条