tomka
tomka

Reputation: 2638

ggplot: how to remove unused factor levels from a facet?

The following code

d1 = data.frame(y=1:2,group=factor(c('A','B'), levels=c('A','B','C')), fac = 'f1')
d2 = data.frame(y=1:3,group=factor(c('A','B','C'), levels=c('A','B','C')), fac = 'f2')
d = rbind(d1,d2)

library(ggplot2)
ggplot( d, aes(x=group, y=y) ) + geom_point(size=3) + facet_grid( ~ fac)

Results in the following plot. How can I remove the unused factor level C from the facet 'f1'? enter image description here

Upvotes: 2

Views: 1329

Answers (1)

aaumai
aaumai

Reputation: 283

Setting scales = free in facet grid will do the trick:

facet_grid( ~ fac, scales = "free")

Upvotes: 5

Related Questions