Open nivretta opened 8 years ago
Unlike other ggplot functions facet_wrap takes in a formula object as its input. That is what you define by adding the ~. While in facet_wrap, the fact that it is a formula doesn't change much, if you use facet_grid the structure of the formula is used to choose which variable separates the rows and which one separates the columns. Try
d <- ggplot(diamonds, aes(carat, price)) +
xlim(0, 2) + stat_binhex(na.rm = TRUE) + theme(aspect.ratio = 1)
d + facet_grid(color~cut)
Two related questions:
1- Why do we have to use the '~' symbol when using facet_wrap, as in class from 9/27, but it's not necessary in other expressions like geom_point? (I excluded the symbol and kept getting an 'object not found' error.)
2- How would I find the answer to this question on Google? This wasn't helpful, since I think this is a basic programming language question.