Reputation: 7517
In my plot below, I was wondering how to keep everything as is but just remove the empty plots?
library(tidyverse)
hsb <- read.csv('https://raw.githubusercontent.com/rnorouzian/e/master/hsb.csv')
hsb <- mutate(hsb, sector= factor(ifelse(sector==0,"pub","cath")))
hsb <- mutate(hsb, sector= relevel(sector, ref= "pub"))
nine <- subset(hsb, sch.id %in% unique(sch.id)[1:9])
nine$sch.id <- factor(nine$sch.id)
ggplot(nine) + aes(ses, math)+ geom_point() + facet_grid(sector~sch.id)+
geom_smooth(method="lm",se=F, aes(color=sector))
Upvotes: 2
Views: 338
Reputation: 56149
I think your faceting should based only on sch.id, try:
ggplot(nine, aes(ses, math)) +
geom_point()+
facet_grid(.~sch.id)+
geom_smooth(method="lm",se=F, aes(color = sector))
Upvotes: 2