我一直试图找到一些类似的资源,但我当前的数据集看起来是这样的:
lwg_date | bon_date | lwg_lengthbon_length||
---|---|---|---|
3月 | 4月 | 1 | 31|
3月 | 4月 | 10 | 14|
3月 | 4月 | 12 | 12|
3月 | 5月 | 19 | 11 |
4月 | 5月 | 17月 | |
4月 | 5月 | 19 | 41 |
4月 | 6月 | 55 | 24 |
4月 | 6月 | 13 | 22 |
8月 | 9月 | 21 | 17 |
8月 | 9月 | 15 | 18 |
library(tidyverse)
data.frame(
stringsAsFactors = FALSE,
lwg_date = c("March","March","March",
"March","April","April","April","April","August",
"August"),
bon_date = c("April","April","April",
"May","May","May","June","June","Sept","Sept"),
lwg_length = c(1L, 10L, 12L, 19L, 5L, 19L, 55L, 13L, 21L, 15L),
bon_length = c(31L, 14L, 12L, 11L, 17L, 41L, 24L, 22L, 17L, 18L)
) %>%
# reshape into type | date | length
pivot_longer(everything(), names_to = c("type", ".value"), names_sep = "_") %>%
# turn date into ordered factor
mutate(date = ifelse(date == "Sept", "September", date),
date = factor(date, levels = month.name)) %>%
# plot histograms
ggplot(aes(length, fill = type)) +
geom_histogram(bins = 5) +
facet_wrap(~date)