【问题标题】:Point Plot with SE for 3 Categorical & 1 Continuous Variable in RR 中 3 个分类变量和 1 个连续变量的 SE 点图
【发布时间】:2015-07-02 00:48:38
【问题描述】:

我正在尝试在具有三个分类变量(mea、tre 和 sex)的设计中生成单个测量值 (len) 的点图。

我制作了一个情节,其中包含我正在寻找的所有内容,分为六个不同的子情节:

但如果可能的话,我希望将它们全部放在一个情节中,优先使用 ggplot。

这是我当前的 R 代码:

ggplot(mydf, aes(x=factor(mea), y=len), group=sex) +
  geom_point() + geom_errorbar(limits, width=0.1) + facet_wrap(~ tre + sex)

以及来自 dput 的样本数据:

structure(list(mea = structure(c(1L, 1L, 1L, 1L, 1L, 1L, 
2L, 2L, 2L, 2L, 2L, 2L), .Label = c("PO_P", "Melaniz"), class = "factor"), 
    tre = structure(c(1L, 1L, 2L, 2L, 3L, 3L, 1L, 1L, 2L, 
    2L, 3L, 3L), .Label = c("a", "b", "c"), class = "factor"), 
    Sex = structure(c(1L, 2L, 1L, 2L, 1L, 2L, 1L, 2L, 1L, 2L, 
    1L, 2L), .Label = c("Male", "Female"), class = "factor"), 
    N = c(26, 26, 25, 25, 27, 27, 14, 13, 12, 11, 14, 13), len = c(10.6615384615385, 
    10.5807692307692, 10.292, 10.6, 10.2851851851852, 10.6518518518519, 
    11.4785714285714, 11.7153846153846, 11.7083333333333, 11.5, 
    11.6214285714286, 11.8923076923077), sd = c(0.869057845290829, 
    0.779753412698774, 0.722218803410712, 0.654471797202395, 
    0.906686148609193, 0.8040141456708, 1.0123685642542, 0.805032249712347, 
    1.13654846981659, 0.822192191643779, 0.833139171519908, 0.739889111580849
    ), se = c(0.170436265829955, 0.152922225659293, 0.144443760682142, 
    0.130894359440479, 0.174491830656674, 0.154732594478434, 
    0.270566879755675, 0.223275773441538, 0.328093282497832, 
    0.247900273203854, 0.222665809666299, 0.205208317689404), 
    ci = c(0.351020060264102, 0.314949219318153, 0.298117269908016, 
    0.270152680174426, 0.358673094717481, 0.318057403068012, 
    0.584524206501098, 0.486476119728297, 0.722128445903482, 
    0.552356230143519, 0.481040236068982, 0.447110515336101)), .Names = c("mea", "tre", "sex", "N", "len", "sd", "se", "ci"), row.names = c(NA, 
-12L), class = "data.frame")

【问题讨论】:

    标签: r graph plot ggplot2


    【解决方案1】:

    要区分所有这些分类变量,您可以使用颜色、形状、大小、点类型等。下面是一个使用颜色和点类型的示例 sextre

    library(ggplot2)
    limits <- aes(ymax=mydf$len+mydf$se, ymin=mydf$len-mydf$se)
    
    ggplot(mydf, aes(x=factor(mea), y=len, color=sex, pch=tre)) +
      geom_point(position=position_dodge(width=0.5)) +
      geom_errorbar(limits, position=position_dodge(width=0.5))
    

    【讨论】:

    • 我认为有三种颜色和两种符号会更好。也许,增加符号的大小也会有所帮助。 ggplot(mydf, aes(x=factor(mea), y=len, color=tre, pch=sex)) + geom_point(position=position_dodge(width=0.5), size = 5) + geom_errorbar(limits, position=position_dodge(width=0.5))
    猜你喜欢
    • 1970-01-01
    • 2023-04-01
    • 1970-01-01
    • 1970-01-01
    • 2019-06-28
    • 2017-09-09
    • 2021-01-04
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多