從以下鏈接Aligning two plots with ggplot2中獲取一個提示,我可以繪製與一個共同的x軸對齊的2個「y」變量。我現在想要做的就是隻能將一個geom_point圖層添加到其中一個方面。該圖層使用與d1具有相同結構的不同數據集(d3)。當我添加圖層時,它在兩個方面都得到了使用。是否有可能只分層點上面。在一個多面圖中爲單個面板添加一個geom圖層
library(ggplot2)
x <- seq(1992, 2002, by = 2)
d1 <- data.frame(x = x, y = rnorm(length(x)))
xy <- expand.grid(x = x, y = x)
d2 <- data.frame(x = xy$x, y = xy$y, z = jitter(xy$x + xy$y))
d3 <- data.frame(x = x, y = 3+rnorm(length(x)))
d1$panel <- "a"
d2$panel <- "b"
d1$z <- d1$x
d <- rbind(d1, d2)
p <- ggplot(data = d, mapping = aes(x = x, y = y))
p <- p + facet_grid(panel ~ ., scale = "free")
p <- p + layer(data = d1, geom = c("line"), stat = "identity")
###*p <- p + layer(data = d3, geom = c("point"))* - This is the layer I intend to add only to the top panel
p <- p + layer(data = d2, geom = "line", stat = "identity")
p
+1,以及一個可重複的示例的句子問題 –