Free Trial

Safari Books Online is a digital library providing on-demand subscription access to thousands of learning resources.

  • Create BookmarkCreate Bookmark
  • Create Note or TagCreate Note or Tag
  • PrintPrint
Share this Page URL
Help

11. Facets > Using Facets with Different Axes

Using Facets with Different Axes

Problem

You want subplots with different ranges or items on their axes.

Solution

Set the scales to "free_x", "free_y", or "free" (Figure 11-3):

# The base plot
p <- ggplot(mpg, aes(x=displ, y=hwy)) + geom_point()

# With free y scales
p + facet_grid(drv ~ cyl, scales="free_y")

# With free x and y scales
p + facet_grid(drv ~ cyl, scales="free")
Top: with free y scales; bottom: with free x and y
            scales
Figure 11-3. Top: with free y scales; bottom: with free x and y scales

Discussion

Each row of subplots has its own y range when free y scales are used; the same applies to columns when free x scales are used.

It’s not possible to directly set the range of each row or column, but you can control the ranges by dropping unwanted data (to reduce the ranges), or by adding geom_blank() (to expand the ranges).


  

You are currently reading a PREVIEW of this book.

                                                                                                                    

Get instant access to over $1 million worth of books and videos.

  

Start a Free Trial


  
  • Safari Books Online
  • Create BookmarkCreate Bookmark
  • Create Note or TagCreate Note or Tag
  • PrintPrint