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

8. Axes > Setting the Range of a Continuous Axis

Setting the Range of a Continuous Axis

Problem

You want to set the range (or limits) of an axis.

Solution

You can use xlim() or ylim() to set the minimum and maximum values of a continuous axis. Figure 8-3 shows one graph with the default y limits, and one with manually set y limits:

p <- ggplot(PlantGrowth, aes(x=group, y=weight)) + geom_boxplot()
# Display the basic graph
p

p + ylim(0, max(PlantGrowth$weight))
Left: box plot with default range; right: with manually
            set range
Figure 8-3. Left: box plot with default range; right: with manually set range

The latter example sets the y range from 0 to the maximum value of the weight column, though a constant value (like 10) could instead be used as the maximum.

Discussion


  

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