我正在尝试放大特定的日期范围,但下面的代码不允许我这样做。在这个图中还有 stat_summary byBleach
和现有 facet by Species
。如果这是一种解决方法,我愿意将每个物种放大为单独的图,但我已经尝试按物种进行子集化,但仍然无法产生预期的结果。
structure(list(ColonyID = c("11", "11", "11", "11", "11", "11",
"11", "12", "12", "12", "12", "12", "12", "12", "238", "238",
"238", "238", "238", "238", "238", "239", "239", "239", "239",
"239", "239", "239"), Species = structure(c(1L, 1L, 1L, 1L, 1L,
1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 2L, 2L, 2L, 2L, 2L, 2L, 2L,
2L, 2L, 2L, 2L, 2L, 2L, 2L), .Label = c("Montipora capitata",
"Porites compressa"), class = "factor"), Bleach = structure(c(1L,
1L, 1L, 1L, 1L, 1L, 1L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L,
2L, 2L, 2L, 2L, 1L, 1L, 1L, 1L, 1L, 1L, 1L), .Label = c("Bleach",
"Non-bleach"), class = "factor"), Date = structure(c(18096, 18155,
18171, 18185, 18199, 18285, 18501, 18096, 18155, 18171, 18185,
18199, 18285, 18501, 18096, 18155, 18171, 18185, 18199, 18285,
18501, 18096, 18155, 18171, 18185, 18199, 18285, 18501), class =
"Date"),
ColorScore2 = c(3L, 4L, 3L, 2L, 2L, 2L, 3L, 2L, 2L, 1L, 2L,
1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 2L, 2L, 2L, 1L, 2L,
2L, 1L)), row.names = c(3L, 43L, 83L, 123L, 163L, 203L, 243L,
4L, 44L, 84L, 124L, 164L, 204L, 244L, 34L, 74L, 114L, 154L, 194L,
234L, 274L, 35L, 75L, 115L, 155L, 195L, 235L, 275L), class =
"data.frame")
a <- ggplot(test, aes(x = Date, y = ColorScore2, color = Bleach)) + stat_summary(aes(group =
Bleach), fun = mean, geom = "point") + stat_summary(aes(group = Bleach), fun = mean, geom =
"line") + scale_color_manual(values = c("Bleach" = "gray", "Non-bleach" = "black")) +
scale_fill_manual(values = c("Bleach" = "gray", "Non-bleach" = "black")) +.
scale_x_date(date_breaks = "1 month", date_labels = "%b", limits = as.Date(c("2019-07-01",
"2020-02-01"))) + facet_grid(. ~ Species) + labs(y = "Bleaching Score", x = "Date") +.
theme_bw()
b <- a + facet_zoom(x = Date >= "2019-09-16" & Date <= "2019-10-30")