我在工作时注意到一些很奇怪的事情
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,因为样本量太小。)
为什么这两张图上的比例不同
geom_density
具有
..count..
被叫来了?相同的时间
..density..
被称为。这两个情节的唯一区别是
x
美学或
日期
或与
posixct公司
. 我很困惑。