[R] Trendline for a subset of data

Steve Murray smurray444 at hotmail.com
Fri Oct 9 16:45:37 CEST 2009

 <CB247343-29EC-495A-BA8E-D5A466BABE53 at comcast.net>
Content-Type: text/plain; charset="iso-8859-1"
Content-Transfer-Encoding: quoted-printable
MIME-Version: 1.0

Thanks for flagging up the 'segments' command. However=2C I'm having troubl=
e getting it to work - this is probably due to me misunderstanding the docu=
mentation for this command.

The plot section of my script appears as follows:

test3 <- 36:45
plot(data_means=2C type=3D"b"=2C pch=3D4=2C ylab=3D""=2C xlab=3D""=2C xaxt=
=3D"n"=2C yaxt=3D"n"=2C col=3D3=2C ylim=3Dc(250=2C380))
abline(lm(data_means[36:45] ~ test3)=2C lty=3D2)

As you can see=2C I'm only plotting points 36 to 45 from the object 'data_m=
eans'. This intentionally results in much white space along the x-axis unti=
l point 36 is reached. However=2C when inserting the trendline=2C this runs=
 along the entire length of the x-axis instead of just through points 36 to=
 45. Ideally=2C a line which slightly overshoots the data subset would look=
 the best=2C but one constrained to the extents of the 36:45 would also do =
the job just fine.

So=2C my question is=2C how do I use 'segments' (or otherwise) to create a =
linear trendline which only extends through points 36:45? (and overshoots a=
t either end very slightly=2C if possible=2C rather than running along the =
entire length of the x-axis).

Many thanks again=2C


> CC: r-help at r-project.org
> From: dwinsemius at comcast.net
> To: smurray444 at hotmail.com
> Subject: Re: [R] Trendline for a subset of data
> Date: Fri=2C 9 Oct 2009 09:27:43 -0400
> On Oct 9=2C 2009=2C at 5:50 AM=2C Steve Murray wrote:
>> Dear all=2C
>> I am using abline(lm ...) to insert a linear trendline through a
>> portion of my data (e.g. dataset[=2C36:45]). However=2C I am finding
>> that whilst the trendline is correctly displayed and representative
>> of the data portion I've chosen=2C the line continues to run beyond
>> this data segment and continues until it intersects the vertical
>> axes at each side of the plot.
>> How do I display the line so that it only runs between point 36 and
>> 45 (as shown in the example above) as doesn't continue to display a
>> line throughout the rest of the plot space?
> ?segments
>> Many thanks=2C
>> Steve
> David Winsemius=2C MD
> Heritage Laboratories
> West Hartford=2C CT
View your other email accounts from your Hotmail inbox. Add them now.=0A=

More information about the R-help mailing list