library(tidyverse)
datasets::ChickWeight # from Base R
ggplot(ChickWeight, aes(Time, weight, group = Chick)) + geom_line()
这里的争吵计算每个时间/重量桶中有多少读数,并标准化为每个时间的“最常见读数的份额”。
ChickWeight %>%
count(Time, weight = 10*floor(weight/10)) %>%
complete(Time, weight = 10*0:30, fill = list(n = 0)) %>%
group_by(Time) %>%
mutate(share = n / max(n)) %>% # weighted for num as % of max for that Time
ungroup() %>%
ggplot(aes(Time, weight, fill = share)) +
geom_tile(width = 2) +
scale_fill_viridis_c(direction = -1)
如果您的数据具有稀疏的时间读数,插入您的行以获得更高的分箱分辨率可能会很有用:
ChickWeight %>%
group_by(Chick) %>%
arrange(Time) %>%
padr::pad_int("Time", step = 0.5) %>%
mutate(weight_approx = approx(Time, weight, Time)$y) %>%
ungroup() %>%
count(Time, weight_approx = 10*floor(weight_approx/10)) %>%
complete(Time, weight_approx = 10*0:60, fill = list(n = 0)) %>%
group_by(Time) %>%
mutate(share = n / sum(n)) %>% # Different weighting option
ungroup() %>%
ggplot(aes(Time, weight_approx, fill = share)) +
geom_tile() +
scale_fill_viridis_c(direction = -1)