1

如果这个问题不言自明,请原谅我,但我仍在努力掌握 R 的更多功能。

我目前正在尝试使用 R 用我在 excel 中绘制的线条重新绘制累积频率。

这是我正在尝试重新创建的图表的图片

我认为我的很多问题都来自有很多没有数据的单元格,因为我不断收到警告:

警告消息:
1:删除了包含缺失值 (geom_path) 的 81 行。
2:删除了包含缺失值 (geom_path) 的 81 行。
3:删除了包含缺失值 (geom_path) 的 81 行。

这是因为每列代表一个记录频率,女巫只发生了 21 天,每个记录周期之间有 20 天的休息时间。

我的数据表

我尝试过使用geom_ steps()geom_points()但最终得到了这些:

使用 geom_step 生成的图形

用 geom_point 生成的图形

当我使用该geom_line()函数时,会创建轴但没有绘制任何内容。

使用 geom_line 生成的图形

x 轴上的日期看起来也很可怕,我尝试使用代码 + theme(axis.text.x = element_text(angle = 90))来旋转标签,但它仍然看起来很糟糕,我不确定它是否只是很多日期。

这是我一直试图为各种 geom 函数工作的代码:

ggplot() +
    geom_point(aes(x = Date, y = d2s1, group = 1), data = cf) +
    geom_point(aes(x = Date, y = d20s1, group = 1), data = cf) +
    geom_point(aes(x = Date, y = d10s1, group = 1), data = cf) +
    theme(axis.text.x = element_text(angle = 90))

ggplot() +
    geom_step(aes(x = Date, y = d2s1, group = 1), data = cf) +
    geom_step(aes(x = Date, y = d20s1, group = 1), data = cf) +
    geom_step(aes(x = Date, y = d10s1, group = 1), data = cf) +
    theme(axis.text.x = element_text(angle = 90))

ggplot() +
    geom_line(aes(x = Date, y = d2s1, group = 1), data = cf) +
    geom_line(aes(x = Date, y = d20s1, group = 1), data = cf) +
    geom_line(aes(x = Date, y = d10s1, group = 1), data = cf) +
    theme(axis.text.x = element_text(angle = 90))

我希望这一切都有意义,并提前感谢大家提供的任何帮助!

我使用read.csv("cf.csv").

我附上了dput(cf)下面的输出。

structure(list(Date = c("08/11/2019", "09/11/2019", "10/11/2019", 
"11/11/2019", "12/11/2019", "13/11/2019", "14/11/2019", "15/11/2019", 
"16/11/2019", "17/11/2019", "18/11/2019", "19/11/2019", "20/11/2019", 
"21/11/2019", "22/11/2019", "23/11/2019", "24/11/2019", "25/11/2019", 
"26/11/2019", "27/11/2019", "28/11/2019", "29/11/2019", "30/11/2019", 
"01/12/2019", "02/12/2019", "03/12/2019", "04/12/2019", "05/12/2019", 
"06/12/2019", "07/12/2019", "08/12/2019", "09/12/2019", "10/12/2019", 
"11/12/2019", "12/12/2019", "13/12/2019", "14/12/2019", "15/12/2019", 
"16/12/2019", "17/12/2019", "18/12/2019", "19/12/2019", "20/12/2019", 
"21/12/2019", "22/12/2019", "23/12/2019", "24/12/2019", "25/12/2019", 
"26/12/2019", "27/12/2019", "28/12/2019", "29/12/2019", "30/12/2019", 
"31/12/2019", "01/01/2020", "02/01/2020", "03/01/2020", "04/01/2020", 
"05/01/2020", "06/01/2020", "07/01/2020", "08/01/2020", "09/01/2020", 
"10/01/2020", "11/01/2020", "12/01/2020", "13/01/2020", "14/01/2020", 
"15/01/2020", "16/01/2020", "17/01/2020", "18/01/2020", "19/01/2020", 
"20/01/2020", "21/01/2020", "22/01/2020", "23/01/2020", "24/01/2020", 
"25/01/2020", "26/01/2020", "27/01/2020", "28/01/2020", "29/01/2020", 
"30/01/2020", "31/01/2020", "01/02/2020", "02/02/2020", "03/02/2020", 
"04/02/2020", "05/02/2020", "06/02/2020", "07/02/2020", "08/02/2020", 
"09/02/2020", "10/02/2020", "11/02/2020", "12/02/2020", "13/02/2020", 
"14/02/2020", "15/02/2020", "16/02/2020", "17/02/2020"), d2s1 = c(6L, 
11L, 13L, 20L, 25L, 35L, 42L, 49L, 49L, 51L, 53L, 54L, 60L, 65L, 
69L, 73L, 76L, 80L, 85L, 86L, 86L, NA, NA, NA, NA, NA, NA, NA, 
NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, 
NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, 
NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, 
NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, 
NA, NA, NA, NA, NA, NA, NA, NA, NA, NA), d10s2 = c(0L, 6L, 8L, 
10L, 11L, 14L, 14L, 15L, 18L, 19L, 21L, 21L, 22L, 22L, 24L, 24L, 
26L, 27L, 31L, 32L, 32L, NA, NA, NA, NA, NA, NA, NA, NA, NA, 
NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, 
NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, 
NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, 
NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, 
NA, NA, NA, NA, NA, NA, NA, NA), d20s1 = c(NA, NA, NA, NA, NA, 
NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, 
NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, 
NA, NA, NA, 3L, 9L, 13L, 19L, 24L, 26L, 32L, 38L, 44L, 46L, 48L, 
50L, 56L, 62L, 64L, 64L, 73L, 83L, 92L, 99L, 105L, NA, NA, NA, 
NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, 
NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, 
NA, NA, NA, NA, NA, NA), d20s2 = c(NA, NA, NA, NA, NA, NA, NA, 
NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, 
NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, 
NA, 0L, 2L, 2L, 3L, 4L, 14L, 15L, 23L, 25L, 27L, 36L, 37L, 38L, 
43L, 43L, 45L, 47L, 50L, 53L, 56L, 57L, NA, NA, NA, NA, NA, NA, 
NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, 
NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, 
NA, NA, NA), d10s1 = c(NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, 
NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, 
NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, 
NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, 
NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, 
NA, NA, NA, NA, NA, NA, NA, 2L, 15L, 19L, 22L, 33L, 34L, 37L, 
37L, 39L, 41L, 48L, 50L, 52L, 56L, 62L, 64L, 65L, 68L, 72L, 77L, 
84L), d2s2 = c(NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, 
NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, 
NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, 
NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, 
NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, 
NA, NA, NA, NA, NA, 4L, 4L, 4L, 4L, 4L, 7L, 9L, 9L, 12L, 12L, 
14L, 17L, 17L, 23L, 24L, 24L, 24L, 26L, 26L, 30L, 33L)), class = "data.frame", row.names = c(NA, 
-102L) 
4

1 回答 1

0

该函数geom_step()有一个参数na.rm来删除NA值,这是FALSE默认的。将其更改为TRUE应该为您提供所需的图。或者,您可以将NA数据更改为零以获得相同的效果。

拥挤的 x 轴是数据作为一个因素而不是日期存储时发生的典型情况。这将与您读取数据的方式有关,您尚未显示。

于 2021-01-30T11:11:11.143 回答