【问题标题】:Plotting a time course of a response variable (that has 2 factors)绘制响应变量的时间过程(具有 2 个因子)
【发布时间】:2022-07-08 12:16:42
【问题描述】:

正如标题所述,我正在尝试绘制响应变量(具有 2 个因子)的时间过程,工作环境基于 Rstudio。 我正在处理一个已经是长格式的数据框。比如:

|Week| Factor1 | Factor2| Response|
 
  1     Sunny     High      2.0
  1     Sunny     High      3.5
  1     Rainy     Low       2.5
  1     Rainy     Low       1.5
  2     Sunny     High      42.5
  2     Sunny     High      435
  2     Rainy     Low       44.5
  2     Rainy     Low       42.5
  3     Sunny     High      80.5
  3     Sunny     High      89.5
  3     Rainy     Low       88.5
  3     Rainy     Low       87.5

    

我想用这个数据框做一个时间课程,但没有取得多大成功,因为我不知道如何让 ggplot2 将响应线绘制为响应因素组合的变量。

帮助...

【问题讨论】:

    标签: r ggplot2 graph


    【解决方案1】:

    你可以试试

    library(dplyr)
    library(ggplot2)
    library(tidyr)
    df %>%
      unite(Factor, c(Factor1, Factor2)) %>%
      ggplot(aes(Week, Response, group = Factor, color = Factor)) +
      geom_line()
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2023-04-09
      • 1970-01-01
      相关资源
      最近更新 更多