Я хочу построить несколько графиков плотности на одном графике, используя ggplot2:
My df
выглядит так:
structure(list(item_count = c(1L, 1L, 2L, 2L, 3L, 3L, 4L, 4L,
5L, 5L, 6L, 8L), created_at = structure(c(18319, 18321, 18319,
18321, 18319, 18321, 18319, 18321, 18319, 18321, 18319, 18321
), class = "Date"), frequency = c(2L, 2L, 3L, 6L, 586L, 419L,
268L, 238L, 5L, 2L, 1L, 1L)), row.names = c(NA, -12L), class = c("grouped_df",
"tbl_df", "tbl", "data.frame"), groups = structure(list(item_count = c(1L,
2L, 3L, 4L, 5L, 6L, 8L), .rows = list(1:2, 3:4, 5:6, 7:8, 9:10,
11L, 12L)), row.names = c(NA, -7L), class = c("tbl_df", "tbl",
"data.frame"), .drop = TRUE))
aka:
# A tibble: 12 x 3
# Groups: item_count [7]
item_count created_at frequency
<int> <date> <int>
1 1 2020-02-27 2
2 1 2020-02-29 2
3 2 2020-02-27 3
4 2 2020-02-29 6
5 3 2020-02-27 586
6 3 2020-02-29 419
7 4 2020-02-27 268
8 4 2020-02-29 238
9 5 2020-02-27 5
10 5 2020-02-29 2
11 6 2020-02-27 1
12 8 2020-02-29 1
Я пытался:
library(tidyverse)
library(ggplot2)
df %>%
ggplot(aes(item_count, frequency), colors=created_at) + geom_density()
получить эту ошибку:
Error: geom_density requires the following missing aesthetics: y
Что я делаю не так?