我已经阅读了很多关于更改标签命令的内容,但我似乎没有在我的图表中正确显示它们。
我想将y轴标签从“HeartRate”更改为“Heart Rate(beats / min)”。
这是我的命令:
df <- data.frame(
Phase = factor(c(0, 0, 1, 1, 2, 2, 3, 3, 4, 4, 5, 5, 6, 6, 7, 7, 8, 8, 9, 9)),
HeartRate = c(67, 70, 70, 73, 82, 83, 104, 106, 73, 86, 74, 65, 86, 82, 94, 108, 73, 81, 67, 68),
group = factor(c("female", "male", "female", "male", "female", "male", "female", "male", "female", "male", "female", "male", "female", "male", "female", "male", "female", "male", "female", "male")),
se = c(4, 7, 4, 9, 5, 9, 8, 14, 6, 15, 3, 6, 6, 9, 4, 14, 3, 8, 4, 5)
)
limits <- aes(ymax = HeartRate + se, ymin=HeartRate - se)
p <- ggplot(df, aes(fill=group, y=HeartRate, x=Phase))
p + geom_bar(position="dodge", stat="identity")
limits <- aes(ymax = HeartRate + se, ymin=HeartRate - se)
p <- ggplot(df, aes(fill=group, y=HeartRate, x=Phase, title="Gender differences in Heart Rate"))
p + geom_bar(position="dodge", stat="identity")
dodge <- position_dodge(width=0.9)
p + geom_bar(position=dodge) + geom_errorbar(limits, position=dodge, width=0.25)
我尝试了一切,但我似乎没有做对。 :(
答案 0 :(得分:1)
添加代码的最后一行:
scale_y_continuous("Heart Rate (beats/min)")
就像这样:
p + geom_bar(position=dodge) + geom_errorbar(limits, position=dodge, width=0.25) + scale_y_continuous("Heart Rate (beats/min)")