Re: [R] Plot multiple similar equations in r

2016-03-02 Thread Berend Hasselman

> On 2 Mar 2016, at 22:22, David L Carlson  wrote:
> 
> Another way would be to use matplot() or matlines():
> 
>> lx<-c(0.4, 0.5, 0.6, 0.7)
>> x <- seq(1, 8, length.out=100)
>> myfun <- function(x, k) {(log(k)-(0.37273*log(x)-1.79389))/0.17941}
>> y <- sapply(lx, function(k) myfun(x, k))
>> matplot(x, a, type="l", col="black", lty=1)
> 
> -

Shouldn't the "a" in the call of matplot  be "y"?

Berend

> 
> David L Carlson
> Department of Anthropology
> Texas A&M University
> College Station, TX 77840-4352
> 
> -Original Message-
> From: R-help [mailto:r-help-boun...@r-project.org] On Behalf Of Dalthorp, 
> Daniel
> Sent: Wednesday, March 2, 2016 1:05 PM
> To: Jinggaofu Shi
> Cc: r-help@R-project.org (r-help@r-project.org)
> Subject: Re: [R] Plot multiple similar equations in r
> 
> Or, if you want easy labels, you can play around with contour graphs.
> 
> ?contour # will give you info on how to make contour plots
> 
> The basic idea is to construct a matrix of z-values...one z for every
> combination of x and y
> contour(x,y,z)
> 
> The x's would then be the x-values you want in
> (0.37273*log(x)-1.79389))/0.17941 for whatever range of x's you want
> The y's would be values from -5 to 5 (or whatever range you want)
> The z's would be values like 0.4, 0.5, etc. or exp(y + x)
> 
> ?outer # will tell you how to create z from x and y
> 
> x<-seq(1,10,length=100) # values for x-axis
> y<-seq(2, 10, length=100) # values for y-axis
> z<-exp(outer((0.37273*log(x)-1.79389)/0.17941,y,"+"))
> contour(x,y,z,levels=seq(.1,1.1,by=.1))
> 
> -Dan
> 
> On Wed, Mar 2, 2016 at 9:03 AM, Jinggaofu Shi  wrote:
> 
>> Hi, there I am new on R. I want to plot a graph like this.
>> 
>> The curves are created by these equations :
>> (log(0.4)-(0.37273*log(x)-1.79389))/0.17941,
>> (log(0.5)-(0.37273*log(x)-1.79389))/0.17941,
>> (log(0.6)-(0.37273*log(x)-1.79389))/0.17941, etc. The equations are
>> similar, the only difference is the first log(XXX). I already manually draw
>> the graph by repeating plot() for each equation. But I think there must be
>> a way to just assign a simple variable like x<-c(0.4,0.5,0.6,0.7), and then
>> plot all the curves automatically. I tried to use data frame to make a set
>> of equations, but failed. Could somebody help me? Thank you very much!
>> 
>> __
>> R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see
>> 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.
>> 
> 
> 
> 
> -- 
> Dan Dalthorp, PhD
> USGS Forest and Rangeland Ecosystem Science Center
> Forest Sciences Lab, Rm 189
> 3200 SW Jefferson Way
> Corvallis, OR 97331
> ph: 541-750-0953
> ddalth...@usgs.gov
> 
>   [[alternative HTML version deleted]]
> 
> __
> R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see
> 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 -- To UNSUBSCRIBE and more, see
> 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 -- To UNSUBSCRIBE and more, see
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] Plot multiple similar equations in r

2016-03-02 Thread David L Carlson
Another way would be to use matplot() or matlines():

> lx<-c(0.4, 0.5, 0.6, 0.7)
> x <- seq(1, 8, length.out=100)
> myfun <- function(x, k) {(log(k)-(0.37273*log(x)-1.79389))/0.17941}
> y <- sapply(lx, function(k) myfun(x, k))
> matplot(x, a, type="l", col="black", lty=1)

-
David L Carlson
Department of Anthropology
Texas A&M University
College Station, TX 77840-4352

-Original Message-
From: R-help [mailto:r-help-boun...@r-project.org] On Behalf Of Dalthorp, Daniel
Sent: Wednesday, March 2, 2016 1:05 PM
To: Jinggaofu Shi
Cc: r-help@R-project.org (r-help@r-project.org)
Subject: Re: [R] Plot multiple similar equations in r

Or, if you want easy labels, you can play around with contour graphs.

?contour # will give you info on how to make contour plots

The basic idea is to construct a matrix of z-values...one z for every
combination of x and y
contour(x,y,z)

The x's would then be the x-values you want in
(0.37273*log(x)-1.79389))/0.17941 for whatever range of x's you want
The y's would be values from -5 to 5 (or whatever range you want)
The z's would be values like 0.4, 0.5, etc. or exp(y + x)

?outer # will tell you how to create z from x and y

x<-seq(1,10,length=100) # values for x-axis
y<-seq(2, 10, length=100) # values for y-axis
z<-exp(outer((0.37273*log(x)-1.79389)/0.17941,y,"+"))
contour(x,y,z,levels=seq(.1,1.1,by=.1))

-Dan

On Wed, Mar 2, 2016 at 9:03 AM, Jinggaofu Shi  wrote:

> Hi, there I am new on R. I want to plot a graph like this.
>
> The curves are created by these equations :
> (log(0.4)-(0.37273*log(x)-1.79389))/0.17941,
> (log(0.5)-(0.37273*log(x)-1.79389))/0.17941,
> (log(0.6)-(0.37273*log(x)-1.79389))/0.17941, etc. The equations are
> similar, the only difference is the first log(XXX). I already manually draw
> the graph by repeating plot() for each equation. But I think there must be
> a way to just assign a simple variable like x<-c(0.4,0.5,0.6,0.7), and then
> plot all the curves automatically. I tried to use data frame to make a set
> of equations, but failed. Could somebody help me? Thank you very much!
>
> __
> R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see
> 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.
>



-- 
Dan Dalthorp, PhD
USGS Forest and Rangeland Ecosystem Science Center
Forest Sciences Lab, Rm 189
3200 SW Jefferson Way
Corvallis, OR 97331
ph: 541-750-0953
ddalth...@usgs.gov

[[alternative HTML version deleted]]

__
R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see
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 -- To UNSUBSCRIBE and more, see
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] Plot multiple similar equations in r

2016-03-02 Thread Dalthorp, Daniel
Or, if you want easy labels, you can play around with contour graphs.

?contour # will give you info on how to make contour plots

The basic idea is to construct a matrix of z-values...one z for every
combination of x and y
contour(x,y,z)

The x's would then be the x-values you want in
(0.37273*log(x)-1.79389))/0.17941 for whatever range of x's you want
The y's would be values from -5 to 5 (or whatever range you want)
The z's would be values like 0.4, 0.5, etc. or exp(y + x)

?outer # will tell you how to create z from x and y

x<-seq(1,10,length=100) # values for x-axis
y<-seq(2, 10, length=100) # values for y-axis
z<-exp(outer((0.37273*log(x)-1.79389)/0.17941,y,"+"))
contour(x,y,z,levels=seq(.1,1.1,by=.1))

-Dan

On Wed, Mar 2, 2016 at 9:03 AM, Jinggaofu Shi  wrote:

> Hi, there I am new on R. I want to plot a graph like this.
>
> The curves are created by these equations :
> (log(0.4)-(0.37273*log(x)-1.79389))/0.17941,
> (log(0.5)-(0.37273*log(x)-1.79389))/0.17941,
> (log(0.6)-(0.37273*log(x)-1.79389))/0.17941, etc. The equations are
> similar, the only difference is the first log(XXX). I already manually draw
> the graph by repeating plot() for each equation. But I think there must be
> a way to just assign a simple variable like x<-c(0.4,0.5,0.6,0.7), and then
> plot all the curves automatically. I tried to use data frame to make a set
> of equations, but failed. Could somebody help me? Thank you very much!
>
> __
> R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see
> 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.
>



-- 
Dan Dalthorp, PhD
USGS Forest and Rangeland Ecosystem Science Center
Forest Sciences Lab, Rm 189
3200 SW Jefferson Way
Corvallis, OR 97331
ph: 541-750-0953
ddalth...@usgs.gov

[[alternative HTML version deleted]]

__
R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see
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] Plot multiple similar equations in r

2016-03-02 Thread Dalthorp, Daniel
A simple solution that will give you an idea of some of the plot parameters:

x<-seq(1,10,length=1000) # values for x-axis
x0<-c(0.4,0.5,0.6,0.7)
miny<-(log(min(x0))-(0.37273*log(max(x))-1.79389))/0.17941 # minimum
y-value to show on graph
maxy<-(log(max(x0))-(0.37273*log(min(x))-1.79389))/0.17941 # maximum
y-value to show on graph
plot(1,1, xlim=range(x), ylim=c(miny,maxy), type='n') # a blank figure to
put lines on
for (i in x0) lines(x,(log(i)-(0.37273*log(x)-1.79389))/0.17941) # putting
the lines on


On Wed, Mar 2, 2016 at 9:03 AM, Jinggaofu Shi  wrote:

> Hi, there I am new on R. I want to plot a graph like this.
>
> The curves are created by these equations :
> (log(0.4)-(0.37273*log(x)-1.79389))/0.17941,
> (log(0.5)-(0.37273*log(x)-1.79389))/0.17941,
> (log(0.6)-(0.37273*log(x)-1.79389))/0.17941, etc. The equations are
> similar, the only difference is the first log(XXX). I already manually draw
> the graph by repeating plot() for each equation. But I think there must be
> a way to just assign a simple variable like x<-c(0.4,0.5,0.6,0.7), and then
> plot all the curves automatically. I tried to use data frame to make a set
> of equations, but failed. Could somebody help me? Thank you very much!
>
> __
> R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see
> 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.
>



-- 
Dan Dalthorp, PhD
USGS Forest and Rangeland Ecosystem Science Center
Forest Sciences Lab, Rm 189
3200 SW Jefferson Way
Corvallis, OR 97331
ph: 541-750-0953
ddalth...@usgs.gov

[[alternative HTML version deleted]]

__
R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see
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] Plot multiple similar equations in r

2016-03-02 Thread Jinggaofu Shi
Hi, there I am new on R. I want to plot a graph like this.

The curves are created by these equations :
(log(0.4)-(0.37273*log(x)-1.79389))/0.17941,
(log(0.5)-(0.37273*log(x)-1.79389))/0.17941,
(log(0.6)-(0.37273*log(x)-1.79389))/0.17941, etc. The equations are
similar, the only difference is the first log(XXX). I already manually draw
the graph by repeating plot() for each equation. But I think there must be
a way to just assign a simple variable like x<-c(0.4,0.5,0.6,0.7), and then
plot all the curves automatically. I tried to use data frame to make a set
of equations, but failed. Could somebody help me? Thank you very much!
__
R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see
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.