我试图用facet_grid制作两个变量的图形。这是我目前的图表:
这几乎是我想要的,除了“改变”方面没有“SURFACE”行,我无法理解为什么。
这是我的数据:
data <- read.table(text = "
lag.distance mantel.statistic Sig WM
1 0.00000 0.44755550 Changed SURFACE
2 36.66667 0.57002150 Changed SURFACE
3 95.00000 -0.40571540 Changed SURFACE
4 203.33333 0.10481760 Changed SURFACE
5 292.50000 -0.48685840 Changed SURFACE
6 0.00000 0.44755550 Changed DEEP
7 36.66667 0.57002150 Changed DEEP
8 95.00000 -0.40571540 Changed DEEP
9 203.33333 0.10481760 Changed DEEP
10 292.50000 -0.48685840 Changed DEEP
11 0.00000 0.46796510 Conserved SURFACE
12 36.66667 0.53094700 Conserved SURFACE
13 95.00000 -0.38027290 Conserved SURFACE
14 203.33333 -0.61828110 Conserved SURFACE
15 292.50000 0.21224900 Conserved SURFACE
16 0.00000 0.20225996 Conserved DEEP
17 34.00000 -0.08036996 Conserved DEEP
18 81.00000 -0.04005344 Conserved DEEP
19 202.25000 0.09716254 Conserved DEEP
20 280.00000 -0.20026720 Conserved DEEP
", header = TRUE)
这是我的代码:
data$WM <- factor(data$WM, levels = c("SURFACE", "DEEP"))
library(ggplot2)
ggplot(data, aes(x=lag.distance,y=mantel.statistic,color=WM)) + geom_line(size=1) + geom_point(size=3) +
labs(colour="Depth", x = "Lag distance (days)", y = "Mantel statistic")+
theme(axis.line = element_line(colour = "black"),
panel.grid.major = element_blank(),
panel.border = element_rect(colour = "lightgray"),
panel.background = element_blank())+
theme(strip.background = element_blank())+
geom_hline(yintercept=0, color = "lightgray")+
facet_grid(Sig~.)
如您所见,我的数据包含“已更改”的“SURFACE”值,为什么不绘制这些值?