【问题标题】:Change axis labels name in ggplot2在ggplot2中更改轴标签名称
【发布时间】:2013-12-13 09:05:19
【问题描述】:

我已经阅读了很多关于更改标签命令的内容,但我似乎没有在我的图表中正确地得到它们。

我想将 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)

我尝试了所有方法,但似乎没有做对。 :(

【问题讨论】:

    标签: r ggplot2 axis-labels


    【解决方案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)")
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2013-02-03
      • 1970-01-01
      • 1970-01-01
      • 2020-05-05
      • 1970-01-01
      • 2018-06-10
      • 1970-01-01
      相关资源
      最近更新 更多