[R] Lines for plot (Sweave)
Gabor Grothendieck
ggrothendieck at gmail.com
Sat Jul 2 05:46:30 CEST 2005
A variation on your idea might be:
fo <- stu.vector ~ x
lines(fo, model.frame(fo), lty=1, col='blue')
On 7/1/05, Don MacQueen <macq at llnl.gov> wrote:
> You can use:
>
> lines(x[!is.na[stu.vector], stu.vector[!is.na(stu.vector)], lty=1,
> col='blue')
>
> -Don
>
> At 1:43 PM -0400 7/1/05, Doran, Harold wrote:
> >Dear List:
> >
> >I am generating a series of plots iteratively using Sweave. In short, a
> >dataframe is subsetted row by row and variable graphics are created
> >conditional on the data in each row. In this particular case, this code
> >ends up generating 17,000 individual plots.
> >
> >In some cases, all student data (this is working with student
> >achievement data) are available and my code below works very well in the
> >sense that a line connects all points. However, in some cases there are
> >missing data and I need to modify my code so that lines are connected
> >through all points even when data are missing.
> >
> >Here is a snip of relevant code. In the actual program, the data in
> >stu.vector and avg.vector are obtained from the dataframe as the
> >programs loops through each row.
> >
> >stu.vector<-c(2500, 2510, NA , 2600)
> >avg.vector<-c(2635, 2589, 2628, 2685)
> >x <- c(0,1,2,3)
> >graph.min <- min(stu.vector,avg.vector ,na.rm=TRUE)-150
> >graph.max <- max(stu.vector,avg.vector ,na.rm=TRUE)+150
> >plot(x, stu.vector, ylim=c(graph.min,graph.max), xlab=" ", ylab="Scaled
> >Score", xaxt='n', pch=2, col='blue', main="Math Growth Rate")
> >points(x, avg.vector, pch=1, col='red')
> >lines(x, stu.vector, lty=1, col='blue')
> >lines(x, avg.vector, lty=3, col='red')
> >
> >If the NA did not exist in the object stu.vector then all points would
> >be connected with lines. However, in some cases data are missing and I
> >need to connect the data in stu.vector with lines. So in this case, the
> >line would connect points 1 and 2, and then 2 and 4 even though point 3
> >is missing.
> >
> >Can anyone suggest how I might do this?
> >
> >Thanks,
> >Harold
> >
> >
> > [[alternative HTML version deleted]]
> >
> >______________________________________________
> >R-help at stat.math.ethz.ch mailing list
> >https://stat.ethz.ch/mailman/listinfo/r-help
> >PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html
>
>
> --
> --------------------------------------
> Don MacQueen
> Environmental Protection Department
> Lawrence Livermore National Laboratory
> Livermore, CA, USA
>
> ______________________________________________
> R-help at stat.math.ethz.ch mailing list
> https://stat.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html
>
More information about the R-help
mailing list