[R] Scatter plot

stephen sefick ssefick at gmail.com
Thu Apr 2 04:28:46 CEST 2009


#excel like regression line but better
reg.line <- function(y,x, data)
{plot(data[,y]~data[,x], main=paste(x,"vs.",y, sep=" "), xlab=x, ylab=y, pch=20)
line <- lm(data[,y]~data[,x])
d <- summary(line)
mtext(3, line=1, adj=0.25 ,text=bquote(bold(R^2== ~ .(d$r.squared))), bty="n")
abline(line)}

x  <- 1:100+rnorm(100)
y <- 1:100
z <- data.frame(x,y)
reg.line(y="y",x="x",data=z)

try this - as an aside does anyone know how to take the x and y out of
quotes.  What can I do differently

hope this helps

Stephen Sefick


On Wed, Apr 1, 2009 at 9:41 PM, Peter Alspach
<PAlspach at hortresearch.co.nz> wrote:
> Tena koe Sueli
>
> ?abline
> ?text
>
> HTH ...
>
> Peter Alspach
>
>> -----Original Message-----
>> From: r-help-bounces at r-project.org
>> [mailto:r-help-bounces at r-project.org] On Behalf Of Sueli Rodrigues
>> Sent: Thursday, 2 April 2009 2:35 p.m.
>> To: r-help at r-project.org
>> Subject: [R] Scatter plot
>>
>>
>> Hi. How do I plot the straight line and r² in a scatter plot
>> using a simple file x~y?
>>
>> Sueli Rodrigues
>>
>> Eng. Agrônoma - UNESP
>> Mestranda - USP/ESALQ
>> PPG-Solos e Nutrição de Plantas
>> Fones (19)93442981
>>       (19)33719762
>>
>> ______________________________________________
>> R-help at r-project.org mailing list
>> https://stat.ethz.ch/mailman/listinfo/r-help
>> PLEASE do read the posting guide
>> http://www.R-project.org/posting-guide.html
>> and provide commented, minimal, self-contained, reproducible code.
>>
>
> The contents of this e-mail are confidential and may be subject to legal privilege.
>  If you are not the intended recipient you must not use, disseminate, distribute or
>  reproduce all or any part of this e-mail or attachments.  If you have received this
>  e-mail in error, please notify the sender and delete all material pertaining to this
>  e-mail.  Any opinion or views expressed in this e-mail are those of the individual
>  sender and may not represent those of The New Zealand Institute for Plant and
>  Food Research Limited.
>
> ______________________________________________
> R-help at r-project.org mailing list
> https://stat.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
> and provide commented, minimal, self-contained, reproducible code.
>



-- 
Stephen Sefick

Let's not spend our time and resources thinking about things that are
so little or so large that all they really do for us is puff us up and
make us feel like gods.  We are mammals, and have not exhausted the
annoying little problems of being mammals.

								-K. Mullis




More information about the R-help mailing list