r-具有两组数据的图面图-多变量(原始数据集结合了两个数据集)



我一直试图找到一些类似的资源,但我当前的数据集看起来是这样的:

lwg_lengthbon_length311412
lwg_date bon_date
3月 4月 1
3月 4月 10
3月 4月 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)

最新更新