Thank you David and Hadley!
Vivek
On Jan 29, 2:38 pm, David Hajage <
dhaj...@gmail.com> wrote:
> Thank you !
>
> David
>
> On Thu, Jan 29, 2009 at 8:50 PM, hadley wickham <
h.wick...@gmail.com> wrote:
> > Hi David,
>
> > That's a good suggestion. I really don't like the way that
> > stat_summary currently works and I think your suggestion could be
> > incorporated directly, so you could just do something like
>
> > c + stat_summary(y = mean, ymin = min, ymax = max, geom = "errorbar")
>
> > I'll think about changing that for the next release.
>
> > Thanks!
>
> > Hadley
>
> > On Thu, Jan 29, 2009 at 4:39 AM, David Hajage <
dhajag...@gmail.com> wrote:
> > > The creation of a new function for stat_summary is not actually very
> > easy.
>
> > > A way could be to include a function "like" this one in ggplot2 ?
>
> > > summary.fun <- function(y, ymin = NULL, ymax = NULL) {
> > > if (is.null(ymin) & is.null(ymax)) {
> > > res <- function(x) y(x)
> > > }
> > > else {
> > > res <- function(data) data.frame("y" = y(data$y), "ymin" =
> > ymin(data$y),
> > > "ymax" = ymax(data$y))
> > > }
> > > return(res)
> > > }
>
> > > c <- qplot(cyl, mpg, data=mtcars)
> > > c + stat_summary(fun = "mean_sdl", geom = "errorbar")
> > > c + stat_summary(fun = summary.fun(mean, min, max), geom = "errorbar")
> > > c + stat_summary(fun = summary.fun(sd), geom = "point", colour = "red")
>
> > > david
>
> > > 2009/1/29 David Hajage <
dhaj...@gmail.com>
>
> > >> Hello Vivek,
>
> > >> I think you must create a new function :
>
> > >> library(ggplot2)
> > >> c <- qplot(cyl, mpg, data=mtcars)
> > >> c + stat_summary(fun = "mean_sdl", geom = "errorbar") # default
>
> > >> mean_sdl_custom <- function(data) {
> > >> data.frame("y" = mean(data$y), "ymin" = mean(data$y) - sd(data$y),
> > >> "ymax" = mean(data$y) + sd(data$y))
> > >> }
>
> > >> c + stat_summary(fun = "mean_sdl_custom", geom = "errorbar") # with the
> > >> new function
>
> > >> David
>
> > >> On Thu, Jan 29, 2009 at 6:14 AM, Vivek <
vivek...@gmail.com> wrote:
>
> > >>> Hi,
>
> > >>> I'm very new to R. I want to make a scatter plot that has of all my
> > >>> categorical data add the mean and standard deviation as error bars.
>
> > >>> I am using the mean_sdl function with stat_summary. The default for
> > >>> this is 2SD. How can I change this to one SD.
>
> > >>> Many thanks!
> > >>> VK
>
> > >>> bn<-read.csv("bn.csv", header = TRUE)
> > >>> plot1 <- ggplot(bn, aes(strain,sum5minavg))
> > >>> plot1<- plot1 + geom_point(colour = "gray59", size = 2)
>
> > >>> #error bars and mean (fromhttp://
had.co.nz/ggplot2/stat_summary.html)