如何解决尝试对数据进行分组并绘制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种样式,因此可以将不同的颜色组用于不同的样式。例如,单独可以使用蓝色和青色,而组可以使用红色和黄色。只是一个意见
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。