Re: [R] Scatter plot / LOESS, or LOWESS for more than one parameter

2012-04-30 Thread David Doyle
First let me say thank you for all the help everyone gave me.

Below is the code I came up with to look at Rainfall pH reading for
Kentucky and Tennessee.

Also there is a more *generic* ver of the code on my web page if anybody
ever needs it in the future.
http://sites.google.com/site/davidsstatistics/using-r/smoothing-curves

Thanks again
David
-


#Load your data.
data <- read.csv("http://www.doylesdartden.com/R/2000-2011_ph_data.csv";,
sep=",")
attach(data)

#Plots the Y and X axis
plot( Year, MF,

#sets the range of the y axis
ylim=range(4.5,5.2),

#sets the symbol type, size, and color for the 1st series
pch=20,cex=0.0, col='black', xlab="Year ", ylab="pH")

#Plots the second series
points( Year, HNWR,
#sets the symbol type, size, and color for the 2nd series
col='blue',pch=20, cex=0.0)

#Plots the 3rd series
points( Year, MCNP,
#sets the symbol type, size, and color for the 3rd series
col='red',pch=20, cex=0.0)

#Plots the 4th series
points( Year, Mackville,
#sets the symbol type, size, and color for the 4th series
col='forestgreen',pch=20, cex=0.0)

#Plots the 5th series
points( Year, GSM,
#sets the symbol type, size, and color for the 5th series
col='purple',pch=20, cex=0.0)



#draw the smooth lines.  NOTE-the span will adjust how much it is smooth
lines( loess.smooth(Year,MF, span = 0.6),col='black', lwd=4, lty=1)

lines( loess.smooth(Year,HNWR, span = 0.6),col='blue',lwd=4, lty=2)

lines( loess.smooth(Year,MCNP, span = 0.6),col='red',lwd=4, lty=3)

lines( loess.smooth(Year,Mackville, span = 0.6),col='forestgreen',lwd=3,
lty=4)

lines( loess.smooth(Year,GSM, span = 0.6),col='purple',lwd=3, lty=5)



#Add Legend to graph.  You can change the size of the box by changing cex =
0.75  Large # makes it larger.
legend("topleft",c("Mulberry Flat KY","Hatchie National Wildlife Refuge
TN", "Mammoth Cave Nat Park", "Mackville KY",  "Great Smokies Mount Nat
Park"),
col = c("black","blue", "red", "forestgreen","purple", "orange",
"limegreen", "gray49", "yellow"),
cex = 0.9,text.col = "black",lty = c(1,2,3,4,5),lwd=c(3),pch = c(-1),
merge = TRUE, bg = 'gray90')


#Add title
title(main="Rainfall pH
Locally Weighted Scatterplot Smoothing Curve")
#done

[[alternative HTML version deleted]]

__
R-help@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.


Re: [R] Scatter plot / LOESS, or LOWESS for more than one parameter

2012-04-25 Thread Greg Snow
You can also use range( MC.pH, MV.pH, na.rm=TRUE).

On Tue, Apr 24, 2012 at 1:29 PM, David Doyle  wrote:
> Hi Greg,
>
> Sloved my own problem.
>
> I had some missing data "NA" in the datasets.  So I manually entered the
> ylim=range(4,6)
> and it worked!!!
>
> Thanks!!
> David
>
>
> On Tue, Apr 24, 2012 at 1:55 PM, David Doyle  wrote:
>>
>> Hi Greg,
>>
>> Thanks,
>>
>> I got the 1st example to work using the following code:
>>
>>
>> data <- read.csv("http://doylesdartden.com/Monthly-pH-example.csv";,
>> sep=",")
>>
>> attach(data)
>>
>> par(mfrow=c(2,1))
>> scatter.smooth( Year, MC.pH )
>> scatter.smooth( Year, MV.pH )
>>
>>
>> This is good but what I'm really looking for is to have them on the same
>> graph.
>>
>>
>> I tried your second example using the code below but got:
>>
>> "Error in plot.window(...) : need finite 'ylim' values"
>>
>> here is the code I used
>>
>>
>> data <- read.csv("http://doylesdartden.com/Monthly-pH-example.csv";,
>> sep=",")
>>
>> attach(data)
>>
>>
>> plot( Year, MC.pH, ylim=range(MC.pH,MV.pH) , col='blue')
>>
>> points( Year, MV.pH, col='green' )
>>
>> lines( loess.smooth(Year,MC.pH), col='blue')
>>
>> lines( loess.smooth(Year,MV.pH), col='green')
>>
>>
>> Thanks again
>>
>> David
>>
>>
>>
>> On Tue, Apr 24, 2012 at 1:45 PM, Greg Snow <538...@gmail.com> wrote:
>>>
>>> Assuming that you want event as the x-axis (horizontal) you can do
>>> something like (untested without reproducible data):
>>>
>>> par(mfrow=c(2,1))
>>> scatter.smooth( event, pH1 )
>>> scatter.smooth( event, pH2 )
>>>
>>> or
>>>
>>> plot( event, pH1, ylim=range(pH1,pH2) , col='blue')
>>> points( event, pH2, col='green' )
>>> lines( loess.smooth(event,pH1), col='blue')
>>> lines( loess.smooth(event,pH2), col='green')
>>>
>>> Only do the second one if pH1 and pH2 are measured on the same scale
>>> in a way that the comparison and any crossings are meaningful or if
>>> there is enough separation (but not too much) that there is no
>>> overlap, but still enough detail.
>>>
>>>
>>>
>>> On Mon, Apr 23, 2012 at 10:40 PM, R. Michael Weylandt
>>>  wrote:
>>> > The scatter plot is easy:
>>> >
>>> > plot(pH1 ~ pH2, data = OBJ)
>>> >
>>> > When you say a loess for each -- how do you break them up? Are there
>>> > repeat values for pH1? If so, this might be hard to do in base
>>> > graphics, but ggplot2 would make it easy:
>>> >
>>> > library(ggplot2)
>>> > ggplot(OBJ, aes(x = pH1, y = pH2)) + geom_point() + stat_smooth() +
>>> > facet_wrap(~factor(pH1))
>>> >
>>> > or something similar.
>>> >
>>> > Michael
>>> >
>>> > On Mon, Apr 23, 2012 at 11:26 PM, David Doyle 
>>> > wrote:
>>> >> Hi folks.
>>> >>
>>> >> If I have the following in my "data"
>>> >>
>>> >> event    pH1    pH2
>>> >> 1            4.0     6.0
>>> >> 2            4.3     5.9
>>> >> 3            4.1     6.1
>>> >> 4            4.0     5.9
>>> >> and on and on. for about 400 events
>>> >>
>>> >> Is there a way I can get R to plot event vs. pH1  and event vs. pH2
>>> >> and
>>> >> then do a loess or lowess line for each??
>>> >>
>>> >> Thanks in advance
>>> >> David
>>> >>
>>> >>        [[alternative HTML version deleted]]
>>> >>
>>> >> __
>>> >> R-help@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.
>>> >
>>> > __
>>> > R-help@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.
>>>
>>>
>>>
>>> --
>>> Gregory (Greg) L. Snow Ph.D.
>>> 538...@gmail.com
>>
>>
>



-- 
Gregory (Greg) L. Snow Ph.D.
538...@gmail.com

__
R-help@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.


Re: [R] Scatter plot / LOESS, or LOWESS for more than one parameter

2012-04-24 Thread David Doyle
Hi Greg,

Sloved my own problem.

I had some missing data "NA" in the datasets.  So I manually entered the
ylim=range(4,6)
and it worked!!!

Thanks!!
David

On Tue, Apr 24, 2012 at 1:55 PM, David Doyle  wrote:

> Hi Greg,
>
> Thanks,
>
> I got the 1st example to work using the following code:
>
>
> data <- read.csv("http://doylesdartden.com/Monthly-pH-example.csv";,
> sep=",")
>
> attach(data)
>
> par(mfrow=c(2,1))
> scatter.smooth( Year, MC.pH )
> scatter.smooth( Year, MV.pH )
>
>
> This is good but what I'm really looking for is to have them on the same
> graph.
>
>
> I tried your second example using the code below but got:
>
> "Error in plot.window(...) : need finite 'ylim' values"
>
> here is the code I used
>
>
> data <- read.csv("http://doylesdartden.com/Monthly-pH-example.csv";,
> sep=",")
>
> attach(data)
>
>
> plot( Year, MC.pH, ylim=range(MC.pH,MV.pH) , col='blue')
>
> points( Year, MV.pH, col='green' )
>
> lines( loess.smooth(Year,MC.pH), col='blue')
>
> lines( loess.smooth(Year,MV.pH), col='green')
>
>
> Thanks again
>
> David
>
>
> On Tue, Apr 24, 2012 at 1:45 PM, Greg Snow <538...@gmail.com> wrote:
>
>> Assuming that you want event as the x-axis (horizontal) you can do
>> something like (untested without reproducible data):
>>
>> par(mfrow=c(2,1))
>> scatter.smooth( event, pH1 )
>> scatter.smooth( event, pH2 )
>>
>> or
>>
>> plot( event, pH1, ylim=range(pH1,pH2) , col='blue')
>> points( event, pH2, col='green' )
>> lines( loess.smooth(event,pH1), col='blue')
>> lines( loess.smooth(event,pH2), col='green')
>>
>> Only do the second one if pH1 and pH2 are measured on the same scale
>> in a way that the comparison and any crossings are meaningful or if
>> there is enough separation (but not too much) that there is no
>> overlap, but still enough detail.
>>
>>
>>
>> On Mon, Apr 23, 2012 at 10:40 PM, R. Michael Weylandt
>>  wrote:
>> > The scatter plot is easy:
>> >
>> > plot(pH1 ~ pH2, data = OBJ)
>> >
>> > When you say a loess for each -- how do you break them up? Are there
>> > repeat values for pH1? If so, this might be hard to do in base
>> > graphics, but ggplot2 would make it easy:
>> >
>> > library(ggplot2)
>> > ggplot(OBJ, aes(x = pH1, y = pH2)) + geom_point() + stat_smooth() +
>> > facet_wrap(~factor(pH1))
>> >
>> > or something similar.
>> >
>> > Michael
>> >
>> > On Mon, Apr 23, 2012 at 11:26 PM, David Doyle 
>> wrote:
>> >> Hi folks.
>> >>
>> >> If I have the following in my "data"
>> >>
>> >> eventpH1pH2
>> >> 14.0 6.0
>> >> 24.3 5.9
>> >> 34.1 6.1
>> >> 44.0 5.9
>> >> and on and on. for about 400 events
>> >>
>> >> Is there a way I can get R to plot event vs. pH1  and event vs. pH2 and
>> >> then do a loess or lowess line for each??
>> >>
>> >> Thanks in advance
>> >> David
>> >>
>> >>[[alternative HTML version deleted]]
>> >>
>> >> __
>> >> R-help@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.
>> >
>> > __
>> > R-help@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.
>>
>>
>>
>> --
>> Gregory (Greg) L. Snow Ph.D.
>> 538...@gmail.com
>>
>
>

[[alternative HTML version deleted]]

__
R-help@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.


Re: [R] Scatter plot / LOESS, or LOWESS for more than one parameter

2012-04-24 Thread David Doyle
Hi Greg,

Thanks,

I got the 1st example to work using the following code:


data <- read.csv("http://doylesdartden.com/Monthly-pH-example.csv";, sep=",")

attach(data)

par(mfrow=c(2,1))
scatter.smooth( Year, MC.pH )
scatter.smooth( Year, MV.pH )


This is good but what I'm really looking for is to have them on the same
graph.


I tried your second example using the code below but got:

"Error in plot.window(...) : need finite 'ylim' values"

here is the code I used


data <- read.csv("http://doylesdartden.com/Monthly-pH-example.csv";, sep=",")

attach(data)


plot( Year, MC.pH, ylim=range(MC.pH,MV.pH) , col='blue')

points( Year, MV.pH, col='green' )

lines( loess.smooth(Year,MC.pH), col='blue')

lines( loess.smooth(Year,MV.pH), col='green')


Thanks again

David


On Tue, Apr 24, 2012 at 1:45 PM, Greg Snow <538...@gmail.com> wrote:

> Assuming that you want event as the x-axis (horizontal) you can do
> something like (untested without reproducible data):
>
> par(mfrow=c(2,1))
> scatter.smooth( event, pH1 )
> scatter.smooth( event, pH2 )
>
> or
>
> plot( event, pH1, ylim=range(pH1,pH2) , col='blue')
> points( event, pH2, col='green' )
> lines( loess.smooth(event,pH1), col='blue')
> lines( loess.smooth(event,pH2), col='green')
>
> Only do the second one if pH1 and pH2 are measured on the same scale
> in a way that the comparison and any crossings are meaningful or if
> there is enough separation (but not too much) that there is no
> overlap, but still enough detail.
>
>
>
> On Mon, Apr 23, 2012 at 10:40 PM, R. Michael Weylandt
>  wrote:
> > The scatter plot is easy:
> >
> > plot(pH1 ~ pH2, data = OBJ)
> >
> > When you say a loess for each -- how do you break them up? Are there
> > repeat values for pH1? If so, this might be hard to do in base
> > graphics, but ggplot2 would make it easy:
> >
> > library(ggplot2)
> > ggplot(OBJ, aes(x = pH1, y = pH2)) + geom_point() + stat_smooth() +
> > facet_wrap(~factor(pH1))
> >
> > or something similar.
> >
> > Michael
> >
> > On Mon, Apr 23, 2012 at 11:26 PM, David Doyle 
> wrote:
> >> Hi folks.
> >>
> >> If I have the following in my "data"
> >>
> >> eventpH1pH2
> >> 14.0 6.0
> >> 24.3 5.9
> >> 34.1 6.1
> >> 44.0 5.9
> >> and on and on. for about 400 events
> >>
> >> Is there a way I can get R to plot event vs. pH1  and event vs. pH2 and
> >> then do a loess or lowess line for each??
> >>
> >> Thanks in advance
> >> David
> >>
> >>[[alternative HTML version deleted]]
> >>
> >> __
> >> R-help@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.
> >
> > __
> > R-help@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.
>
>
>
> --
> Gregory (Greg) L. Snow Ph.D.
> 538...@gmail.com
>

[[alternative HTML version deleted]]

__
R-help@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.


Re: [R] Scatter plot / LOESS, or LOWESS for more than one parameter

2012-04-24 Thread David Doyle
Hi Michael,

What I run into is that I have a lot of time-series data from groundwater
wells but when plot it..it becomes way to busy to see what is going on.

For example, here is the code to load and plot my Mammoth Cave rainfall pH
data

#Load data from web page
data <- read.csv("http://doylesdartden.com/Monthly-pH-example.csv";, sep=",")
attach(data)

#Plot data
plot(Year,MC.pH,pch="*",col="blue")

# Apply loess smoothing
y.loess <- loess(y ~ x, span=0.8, data.frame(x=Year, y=MC.pH))

# Compute loess smoothed values for all points along the curve
y.predict <- predict(y.loess, data.frame(x=Year))

# Plots the curve.
lines(Year,y.predict,lwd=3,col="blue")

#Done

What I would like to do is to have it plot the MC.pH data vs. year and the
MV.pH vs. year data and then draw two different smoothed lines for the
data.  This way I could really just look at the two smoothed lines and see
how the data is trending in relationship to each other.

Thanks
David


On Mon, Apr 23, 2012 at 11:40 PM, R. Michael Weylandt <
michael.weyla...@gmail.com> wrote:

> The scatter plot is easy:
>
> plot(pH1 ~ pH2, data = OBJ)
>
> When you say a loess for each -- how do you break them up? Are there
> repeat values for pH1? If so, this might be hard to do in base
> graphics, but ggplot2 would make it easy:
>
> library(ggplot2)
> ggplot(OBJ, aes(x = pH1, y = pH2)) + geom_point() + stat_smooth() +
> facet_wrap(~factor(pH1))
>
> or something similar.
>
> Michael
>
> On Mon, Apr 23, 2012 at 11:26 PM, David Doyle 
> wrote:
> > Hi folks.
> >
> > If I have the following in my "data"
> >
> > eventpH1pH2
> > 14.0 6.0
> > 24.3 5.9
> > 34.1 6.1
> > 44.0 5.9
> > and on and on. for about 400 events
> >
> > Is there a way I can get R to plot event vs. pH1  and event vs. pH2 and
> > then do a loess or lowess line for each??
> >
> > Thanks in advance
> > David
> >
> >[[alternative HTML version deleted]]
> >
> > __
> > R-help@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.
>

[[alternative HTML version deleted]]

__
R-help@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.


Re: [R] Scatter plot / LOESS, or LOWESS for more than one parameter

2012-04-24 Thread Greg Snow
Assuming that you want event as the x-axis (horizontal) you can do
something like (untested without reproducible data):

par(mfrow=c(2,1))
scatter.smooth( event, pH1 )
scatter.smooth( event, pH2 )

or

plot( event, pH1, ylim=range(pH1,pH2) , col='blue')
points( event, pH2, col='green' )
lines( loess.smooth(event,pH1), col='blue')
lines( loess.smooth(event,pH2), col='green')

Only do the second one if pH1 and pH2 are measured on the same scale
in a way that the comparison and any crossings are meaningful or if
there is enough separation (but not too much) that there is no
overlap, but still enough detail.



On Mon, Apr 23, 2012 at 10:40 PM, R. Michael Weylandt
 wrote:
> The scatter plot is easy:
>
> plot(pH1 ~ pH2, data = OBJ)
>
> When you say a loess for each -- how do you break them up? Are there
> repeat values for pH1? If so, this might be hard to do in base
> graphics, but ggplot2 would make it easy:
>
> library(ggplot2)
> ggplot(OBJ, aes(x = pH1, y = pH2)) + geom_point() + stat_smooth() +
> facet_wrap(~factor(pH1))
>
> or something similar.
>
> Michael
>
> On Mon, Apr 23, 2012 at 11:26 PM, David Doyle  wrote:
>> Hi folks.
>>
>> If I have the following in my "data"
>>
>> event    pH1    pH2
>> 1            4.0     6.0
>> 2            4.3     5.9
>> 3            4.1     6.1
>> 4            4.0     5.9
>> and on and on. for about 400 events
>>
>> Is there a way I can get R to plot event vs. pH1  and event vs. pH2 and
>> then do a loess or lowess line for each??
>>
>> Thanks in advance
>> David
>>
>>        [[alternative HTML version deleted]]
>>
>> __
>> R-help@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.
>
> __
> R-help@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.



-- 
Gregory (Greg) L. Snow Ph.D.
538...@gmail.com

__
R-help@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.


Re: [R] Scatter plot / LOESS, or LOWESS for more than one parameter

2012-04-23 Thread R. Michael Weylandt
The scatter plot is easy:

plot(pH1 ~ pH2, data = OBJ)

When you say a loess for each -- how do you break them up? Are there
repeat values for pH1? If so, this might be hard to do in base
graphics, but ggplot2 would make it easy:

library(ggplot2)
ggplot(OBJ, aes(x = pH1, y = pH2)) + geom_point() + stat_smooth() +
facet_wrap(~factor(pH1))

or something similar.

Michael

On Mon, Apr 23, 2012 at 11:26 PM, David Doyle  wrote:
> Hi folks.
>
> If I have the following in my "data"
>
> event    pH1    pH2
> 1            4.0     6.0
> 2            4.3     5.9
> 3            4.1     6.1
> 4            4.0     5.9
> and on and on. for about 400 events
>
> Is there a way I can get R to plot event vs. pH1  and event vs. pH2 and
> then do a loess or lowess line for each??
>
> Thanks in advance
> David
>
>        [[alternative HTML version deleted]]
>
> __
> R-help@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.

__
R-help@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.


[R] Scatter plot / LOESS, or LOWESS for more than one parameter

2012-04-23 Thread David Doyle
Hi folks.

If I have the following in my "data"

eventpH1pH2
14.0 6.0
24.3 5.9
34.1 6.1
44.0 5.9
and on and on. for about 400 events

Is there a way I can get R to plot event vs. pH1  and event vs. pH2 and
then do a loess or lowess line for each??

Thanks in advance
David

[[alternative HTML version deleted]]

__
R-help@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.