Я заметил что-то очень странное при работе с Date
и POSIXct
объектами. Смотрите следующий код:
library(tidyverse)
library(Rmisc)
test <- structure(list(
date = structure(c(
16863, 16866, 16862, 16743,
16741, 16819, 16820, 16969, 16896, 16636, 16855, 16715, 16842,
16899, 16859, 16860, 16827, 16823, 16912, 16878, 16848, 16839,
16901, 16833, 16896, 16841, 16735, 16800, 16781, 16903
), class = "Date"),
group = structure(c(
1L, 1L, 2L, 2L, 2L, 2L, 2L, 1L, 1L, 2L,
2L, 1L, 1L, 2L, 1L, 2L, 2L, 2L, 1L, 1L, 1L, 2L, 1L, 2L, 1L,
2L, 1L, 2L, 2L, 2L
), .Label = c("0", "1"), class = "factor")
), row.names = c(
NA,
-30L
), class = c("tbl_df", "tbl", "data.frame"))
test$posix <- as.POSIXct(test$date)
p1 <- ggplot(
test,
aes(x = date, group = group, colour = group, fill = group)
) +
stat_density(aes(y = ..count..), alpha = 0.4)
p2 <- ggplot(
test,
aes(x = posix, group = group, colour = group, fill = group)
) +
stat_density(aes(y = ..count..), alpha = 0.4)
multiplot(p1, p2)
Это приводит к следующему графику: см. Ось Y. (Количество <1, потому что размер выборки очень мал.) </p>
![enter image description here](https://i.stack.imgur.com/ttIhq.png)
Почему шкалы отличаются на этих двух графиках, когда вызывается geom_density
с ..count..
? То же самое, когда вызывается ..density..
. Единственная разница между этими двумя сюжетами - это призыв к x
эстетике либо с Date
, либо с POSIXct
. Я довольно озадачен.