

# Create a title with a red, bold/italic font axis(2, las=1, at=4*0:g_range) # Create box around plot box() # Graph trucks with red dashed line and square points # Make x axis using Mon-Fri labels axis(1, at=1:5, lab=c("Mon","Tue","Wed","Thu","Fri")) # Make y axis with horizontal labels that display ticks at # every 4 marks. Plot(cars, type="o", col="blue", ylim= g_range, Turn off axes and # annotations (axis labels) so we can specify them ourself # Calculate range from 0 to max value of cars and trucks g_range <- range(0, cars, trucks) # Graph autos using y axis that ranges from 0 to max # value in cars or trucks vector. We'llĪlso compute the y-axis values using the max function so any changes to ourĭata will be automatically reflected in our graph. Next let's change the axes labels to match our data and add a legend. Title(main="Autos", col.main="red", font.main=4) Plot(cars, type="o", col="blue", ylim=c(0,12)) # Graph trucks with red dashed line and square points lines(trucks, type="o", pch=22, lty=2, col="red") # Create a title with a red, bold/italic font Trucks <- c(2, 5, 4, 5, 12) # Graph cars using a y axis that ranges from 0 to 12 Will be large enough to fit the truck data: Now let's add a red line for trucks and specify the y-axis range directly so it Plot(cars, type="o", col="blue") # Create a title with a red, bold/italic font title(main="Autos", col.main="red", font.main=4) # Graph cars using blue points overlayed by a line Let's add a title, a line to connect the points, and some color: # Graph the cars vector with all defaults The graph produced by each example is shown on the right.įirst we'll produce a very simple graph using the values in the car vector: The areas in bold indicate new text that was added to the previousĮxample. The following is an introduction for producing simple graphs with the
