Skip to content

Plotting extra lines on scatterplot

2 messages · Tony Laidig, John Fox

#
Hello Everyone-
I'm in the process of slowly learning R and am having a little bit of 
trouble plotting an extra line onto a scatterplot. I'm sure the answer 
is quite simple but I am stumped.

The code I am using is:

headways <- read.table("headways.csv", header=TRUE, sep=",", 
na.strings="", dec=".", strip.white=TRUE)
plot.new()
scatterplot(dechway~dechr, reg.line=FALSE, smooth=TRUE, labels=F, 
boxplots='y', span=0.5, xlab="Time", ylab="Headway", ylim=c(0,9), 
data=headways)
lines(headways$dechr, headways$schedule)

A subset of the dataset I'm working with is at 
http://web.mit.edu/c64/www/headways.csv .

The extra line, plotted with lines(), should be right at 4, but is 
actually below where it should be. I assume that I'm using the wrong 
function to plot this line, as there are many ways to do it, but have 
not the experience to know which function is appropriate to use with 
scatterplot().

Thank you for all of your help.
-Tony
#
Dear Tony,
"reset.par: if TRUE then plotting parameters are reset to their previous
values when scatterplot exits; if FALSE then the mar and mfcol parameters
are altered for the current plotting device. Set to FALSE if you want to add
graphical elements (such as lines) to the plot."

I hope this helps,
 John
On
http://www.R-project.org/posting-guide.html