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

2. Quickly Exploring Data > Creating a Line Graph

Creating a Line Graph

Problem

You want to create a line graph.

Solution

To make a line graph using plot() (Figure 2-3, left), pass it a vector of x values and a vector of y values, and use type="l":

plot(pressure$temperature, pressure$pressure, type="l")
Left: line graph with base graphics; right: with points
            and another line
Figure 2-3. Left: line graph with base graphics; right: with points and another line

To add points and/or multiple lines (Figure 2-3, right), first call plot() for the first line, then add points with points() and additional lines with lines():

plot(pressure$temperature, pressure$pressure, type="l")
points(pressure$temperature, pressure$pressure)

lines(pressure$temperature, pressure$pressure/2, col="red")
points(pressure$temperature, pressure$pressure/2, col="red")

  

You are currently reading a PREVIEW of this book.

                                                                                                                    

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

  

Start a Free 10-Day Trial


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