Re: [R] plotting a function with given formula in ggplot2

2011-11-10 Thread Dennis Murphy
Hi: Borrowing from this thread, courtesy of Brian Diggs: http://groups.google.com/group/ggplot2/browse_thread/thread/478f9e61d41b4678/ed323c497db61156?lnk=gst&q=stat_function#ed323c497db61156 ...here's a small reproducible example: ddf <- data.frame(x = 1:10, y = 0.4 + 0.6 * (1:10) + rnorm(10))

Re: [R] plotting a function with given formula in ggplot2

2011-11-10 Thread Curiouslearn
Thanks Rainer. I did not know about dput(). Here is the data. mom_hs <- c(1, 1, 1, 1, 1, 0, 1, 1, 1, 1, 1, 1, 1, 1, 0, 1, 1, 1, 1, 0, 1, 1, 1, 1, 0, 1, 1, 1, 1, 1, 1, 1, 1, 0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 0, 1, 0, 0, 1, 1, 1, 0, 1, 1, 1, 1, 1, 1, 1, 1, 0, 0, 1, 1,

[R] plotting a function with given formula in ggplot2

2011-11-10 Thread Curiouslearn
Hi All, I have a scatter plot produced using ggplot2 and I want to add the regression line to this scatter plot. I suppose I can use geom_smooth() to do this, but for the sake of learning ( I am new both to R and ggplot2), I want to try and add it as a function (something that curve() does in the

Re: [R] Plotting a function that includes logical operators

2011-07-27 Thread Duncan Murdoch
On 27/07/2011 9:21 AM, dean123 wrote: Hi David, I am trying to define t as a single numeric value and not as a vector.. I want the function to realise that if I call test(t) and t is less than equal 10 return zero, if t greater than 10 return 2*t. Am i missing some code in which to define t a nu

Re: [R] Plotting a function that includes logical operators

2011-07-27 Thread dean123
Hi David, I am trying to define t as a single numeric value and not as a vector.. I want the function to realise that if I call test(t) and t is less than equal 10 return zero, if t greater than 10 return 2*t. Am i missing some code in which to define t a numeric value instead of a vector? Also,

Re: [R] Plotting a function that includes logical operators

2011-07-27 Thread David Winsemius
On Jul 27, 2011, at 3:01 AM, dean123 wrote: I am trying to plot the following function over the range 0-100 test <- function(t){{ if (t<=10) x<-t*0 else x<-2*t } x } Two problems I see. The first is the one described fairly clearly by the error message: Read: ?"if" It is not designed

[R] Plotting a function that includes logical operators

2011-07-27 Thread dean123
I am trying to plot the following function over the range 0-100 test <- function(t){{ if (t<=10) x<-t*0 else x<-2*t } x } when I use plot(test,0,100) the GUI produces the following; "Warning message: In if (t <= 10) x <- t * 0 else x <- 2 * t : the condition has length > 1 and only the first e

Re: [R] plotting a function

2010-03-31 Thread Francisco J. Zagmutt
Take a look at the examples in ?curve. As suggested by Erik, in the future please read the posting guide so you can get a more accurate response. Regards, Francisco Dr. Francisco J. Zagmutt Vose Consulting 1643 Spruce St., Boulder Boulder, CO, 80302 USA www.voseconsulting.com Jin wrote: He

Re: [R] plotting a function

2010-03-31 Thread Erik Iverson
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code. Jin wrote: Hello Dear, I am trying to plot a function to see a minimum point (actually, using "optim"). For example, 1. y=f(x) 2. x has a range 3. pl

[R] plotting a function

2010-03-31 Thread Jin
Hello Dear, I am trying to plot a function to see a minimum point (actually, using "optim"). For example, 1. y=f(x) 2. x has a range 3. plot(x,y) to see a point x minimizing y I tried "plot(x,y)", but it made an error. Am I doing a right way? Thanks, Jin -- View this message in context: htt

Re: [R] Plotting a function with a histogram

2008-05-09 Thread Amit Soni
Thank you for your replies. I figured out that curve has an option of add which adds it to a previously existing graph. Thank you, Amit On Fri, May 9, 2008 at 10:07 AM, Amit Soni <[EMAIL PROTECTED]> wrote: > Hi, > > I have a histogram of an array of numbers. > hist(v,10) > > How can I plot a fun

[R] Plotting a function with a histogram

2008-05-09 Thread Amit Soni
Hi, I have a histogram of an array of numbers. hist(v,10) How can I plot a function, say a semi circle, curve(sqrt(2.25-x*x), -1.5,1.5) in the same graph? Thank you [[alternative HTML version deleted]] __ R-help@r-project.org mailing list htt