如何将几何平滑线添加到镶嵌面栅格,但不包括R中的特定镶嵌面?

如何将几何平滑线添加到镶嵌面栅格,但不包括R中的特定镶嵌面?,r,facet,non-linear-regression,R,Facet,Non Linear Regression,我想从以下三个方面排除趋势线: 草坪;2014年 草丛;2013年 草丛;2015年 我曾尝试使用subset(),但我不知道如何删除或排除geom_smooth()中的特定观测值 plot这有点难看,但应该会给出期望的结果 plot <- ggplot(data, aes(x=CWD, y=Amount)) + geom_point(aes(colour = Year),size=2) + geom_smooth(data = data[-which(data$CoverType ==

我想从以下三个方面排除趋势线:

草坪;2014年
草丛;2013年
草丛;2015年

我曾尝试使用subset(),但我不知道如何删除或排除geom_smooth()中的特定观测值


plot这有点难看,但应该会给出期望的结果

plot <- ggplot(data, aes(x=CWD, y=Amount)) + geom_point(aes(colour = Year),size=2) + 
geom_smooth(data = data[-which(data$CoverType == "Lawn" & data$Year == "2014" | data$CoverType == "Tussock" & data$Year %in% c("2013","2015")),] ,method = "lm", formula = y ~ splines::bs(x, 3), color = "black",se = FALSE) +
facet_grid(CoverType~Year,margins=FALSE,scales="free_x",space = "fixed")

plot谢谢你!它起作用了,但不幸的是,它给了我与我想要的相反的结果。我想排除这三个方面,但其他方面都有趋势线。对不起,误读了这个问题。最简单的解决方案是将dum==1更改为dum==0。我将编辑我的答案以给出正确的解决方案。如果这是你问题的答案,你能接受吗?
plot <- ggplot(data, aes(x=CWD, y=Amount)) + geom_point(aes(colour = Year),size=2) + 
geom_smooth(data = data[-which(data$CoverType == "Lawn" & data$Year == "2014" | data$CoverType == "Tussock" & data$Year %in% c("2013","2015")),] ,method = "lm", formula = y ~ splines::bs(x, 3), color = "black",se = FALSE) +
facet_grid(CoverType~Year,margins=FALSE,scales="free_x",space = "fixed")
data$dum<-ifelse(data$CoverType == "Lawn" & data$Year == "2014" | data$CoverType == "Tussock" & data$Year %in% c("2013","2015"),1,0)
plot <- ggplot(data, aes(x=CWD, y=Amount)) + geom_point(aes(colour = Year),size=2) + 
geom_smooth(data = subset(data, dum==0) ,method = "lm", formula = y ~ splines::bs(x, 3), color = "black",se = FALSE) +
facet_grid(CoverType~Year,margins=FALSE,scales="free_x",space = "fixed")