Re: [R] Error bars and CI
Hi Dennis, I have copied the 'r' group. Could you explain ? Why can't we compute CI and error bars using this data set ? The graph generated has equal-sized error bars and a 99% confidence band. Groups are not needed here. But the error bar and CI calculations could be incorrect but I am able to draw this. V1 IDX 1 0.796 1 2 0.542 2 3 0.510 3 4 0.617 4 5 0.482 5 6 0.387 6 7 0.272 7 8 0.536 8 9 0.498 9 10 0.402 10 11 0.328 11 12 0.542 12 13 0.299 13 14 0.647 14 15 0.291 15 16 0.815 16 17 0.680 17 18 0.363 18 19 0.560 19 20 0.334 20 Assume the dataframe is 'jc'. print(summary(jc$V1)) error - qt(0.995,df=length(jc$V1)-1)*sd(jc$V1)/sqrt(length(jc$V1)) error1 - mean(jc$V1)-error error2 - mean(jc$V1)+error print(error1) print(error2) q - qplot(geom = line,jc$IDX,jc$V1, colour='red')+geom_errorbar(aes(x=jc$IDX, ymin=jc$V1-sd(jc$V1), ymax=jc$V1+sd(jc$V1)), width=0.25)+ geom_ribbon(aes(x=jc$IDX, y=jc$V1, ymin=error1, ymax=error2),fill=ivory2,alpha = 0.4)+ xlab('Iterations') + ylab(Java Collections)+theme_bw() Thanks, Mohan -Original Message- From: Dennis Murphy [mailto:djmu...@gmail.com] Sent: Wednesday, June 17, 2015 8:42 PM To: Radhakrishnan, Mohan (Cognizant) Subject: Re: [R] Error bars and CI Q: How do you expect to get error bars when you plot groups having samples of size 1? If you are not grouping, then what is the point of trying to manufacture variation where none exists? I'd suggest you think a little more deeply about what you can achieve with the available data. This plot visualizes the data you posted. Every point is accounted for. I named the input data frame DF. ggplot(DF, aes(x = IDX, y = V1)) + geom_line() + geom_point() If you don't have replicate data at each unique x-value you want to plot, you cannot legitimately plot error bars, confidence intervals or any other visual that describes a (summary of) a distribution. If the values of V1 are supposed to represent averages that come from other data set, then you should have a corresponding column of standard deviations/standard errors, and *then* you can plot error bars, CIs, etc. Without a legitimate measure of variation in your input data frame, I don't see how you can possibly generate a line graph with accompanying error bars/CIs. Dennis On Wed, Jun 17, 2015 at 1:13 AM, mohan.radhakrish...@cognizant.com wrote: I think it could be something like this. But the mean is for the entire set. Not groups. I get a graph with this code but error bars are not there. p-ggplot(jc,aes(IDX,V1,colour=V1)) p - p + stat_summary(fun.y=mean,geom=point) p - p + stat_summary(fun.y=mean,geom=line) p - p + stat_summary(fun.data=mean_cl_normal,conf.int = .99, geom=errorbar, width=0.2) Thanks, Mohan -Original Message- From: Radhakrishnan, Mohan (Cognizant) Sent: Wednesday, June 17, 2015 12:54 PM To: 'Dennis Murphy' Cc: r-help@r-project.org Subject: RE: [R] Error bars and CI Your sample code is working. But I am missing the logic when my dataset is involved. My full dataset is this. It is the V1 column I am interested in. I am not 'grouping' here. V1 IDX 1 0.796 1 2 0.542 2 3 0.510 3 4 0.617 4 5 0.482 5 6 0.387 6 7 0.272 7 8 0.536 8 9 0.498 9 10 0.402 10 11 0.328 11 12 0.542 12 13 0.299 13 14 0.647 14 15 0.291 15 16 0.815 16 17 0.680 17 18 0.363 18 19 0.560 19 20 0.334 20 Thanks, Mohan -Original Message- From: Dennis Murphy [mailto:djmu...@gmail.com] Sent: Tuesday, June 16, 2015 1:18 AM To: Radhakrishnan, Mohan (Cognizant) Subject: Re: [R] Error bars and CI Hi: Firstly, your dplyr code to generate the summary data frame is unnecessary and distracting, particularly since you didn't provide the input data set; you are asked to provide a *minimal* reproducible example, which you could easily have done with a built-in data set. That said, to get what I perceive you want, I used the InsectSprays data from the autoloaded datasets package. # Function to compute standard error of a mean sem - function(x) sqrt(var(x)/length(x)) ## Use insectSprays data for illustration ## Compute mean and SE of count for each level of spray library(dplyr) library(ggplot2) insectSumm - InsectSprays %% group_by(spray) %% summarise(mean = mean(count), se = sem(count)) # Since the x-variable is a factor, need to map group = 1 to # draw lines between factor levels. geom_pointrange() can be # used to produce the 99% CIs per factor level, geom_errorbar() # for the mean +/- SE. I ordered the geoms so that the errorbar # is last, but if you want it (mostly) overwritten, put the # geom_pointrange() call last. ggplot(insectSumm, aes(x = spray, y = mean)) + theme_bw() + geom_line(aes(group = 1), size = 1, color = darkorange) + geom_pointrange(aes(ymin = mean
Re: [R] Error bars and CI
Your sample code is working. But I am missing the logic when my dataset is involved. My full dataset is this. It is the V1 column I am interested in. I am not 'grouping' here. V1 IDX 1 0.796 1 2 0.542 2 3 0.510 3 4 0.617 4 5 0.482 5 6 0.387 6 7 0.272 7 8 0.536 8 9 0.498 9 10 0.402 10 11 0.328 11 12 0.542 12 13 0.299 13 14 0.647 14 15 0.291 15 16 0.815 16 17 0.680 17 18 0.363 18 19 0.560 19 20 0.334 20 Thanks, Mohan -Original Message- From: Dennis Murphy [mailto:djmu...@gmail.com] Sent: Tuesday, June 16, 2015 1:18 AM To: Radhakrishnan, Mohan (Cognizant) Subject: Re: [R] Error bars and CI Hi: Firstly, your dplyr code to generate the summary data frame is unnecessary and distracting, particularly since you didn't provide the input data set; you are asked to provide a *minimal* reproducible example, which you could easily have done with a built-in data set. That said, to get what I perceive you want, I used the InsectSprays data from the autoloaded datasets package. # Function to compute standard error of a mean sem - function(x) sqrt(var(x)/length(x)) ## Use insectSprays data for illustration ## Compute mean and SE of count for each level of spray library(dplyr) library(ggplot2) insectSumm - InsectSprays %% group_by(spray) %% summarise(mean = mean(count), se = sem(count)) # Since the x-variable is a factor, need to map group = 1 to # draw lines between factor levels. geom_pointrange() can be # used to produce the 99% CIs per factor level, geom_errorbar() # for the mean +/- SE. I ordered the geoms so that the errorbar # is last, but if you want it (mostly) overwritten, put the # geom_pointrange() call last. ggplot(insectSumm, aes(x = spray, y = mean)) + theme_bw() + geom_line(aes(group = 1), size = 1, color = darkorange) + geom_pointrange(aes(ymin = mean - qt(.995, 11) * se, ymax = mean + qt(.995, 11) * se), size = 1.5, color = firebrick) + geom_errorbar(aes(ymin = mean - se, ymax = mean + se), width = 0.2, size = 1) Clearly, you can pipe all the way through the ggplot() call, but I wanted to check the contents of the summary data frame first. Dennis On Mon, Jun 15, 2015 at 3:51 AM, mohan.radhakrish...@cognizant.com wrote: Hi, I want to plot a line graph using this data. IDX is x-axis and V1 is y-axis. I also want standard error bars and 99% CI to be shown. My code is given below. The section that plots the graph is the problem. I don't see all the points in the line graph with error bars. How can I also show the 99% CI in the graph ? V1 IDX 1 0.987 21 2 0.585 22 3 0.770 23 4 0.711 24 library(stringr) library(dplyr) library(ggplot2) data - read.table(D:\\jmh\\jmh.txt,sep=\t) final -data %% select(V1) %% filter(grepl(^Iteration, V1)) %% mutate(V1 = str_extract(V1, \\d+\\.\\d*)) final - mutate(final,IDX = 1:n()) jc - final %% filter(IDX 21) #Convert to numeric jc - data.frame(sapply(jc, function(x) as.numeric(as.character(x print(jc) # The following section is the problem. sem - function(x){ sd(x)/sqrt(length(x)) } meanvalue - apply(jc,2,mean) semvalue - apply(jc, 2, sem) mean_sem - data.frame(mean= meanvalue, sem= semvalue, group=names(jc)) #larger font theme_set(theme_gray(base_size = 20)) #plot using ggplot p - ggplot(mean_sem, aes(x=group, y=mean)) + geom_line(stat='identity') + geom_errorbar(aes(ymin=mean-sem, ymax=mean+sem), width=.2) print(p) Thanks, Mohan This e-mail and any files transmitted with it are for the sole use of the intended recipient(s) and may contain confidential and privileged information. If you are not the intended recipient(s), please reply to the sender and destroy all copies of the original message. Any unauthorized review, use, disclosure, dissemination, forwarding, printing or copying of this email, and/or any action taken in reliance on the contents of this e-mail is strictly prohibited and may be unlawful. Where permitted by applicable law, this e-mail and other e-mail communications sent to and from Cognizant e-mail addresses may be monitored. [[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. This e-mail and any files transmitted with it are for the sole use of the intended recipient(s) and may contain confidential and privileged information. If you are not the intended recipient(s), please reply to the sender and destroy all copies of the original message. Any unauthorized review
Re: [R] Error bars and CI
I think it could be something like this. But the mean is for the entire set. Not groups. I get a graph with this code but error bars are not there. p-ggplot(jc,aes(IDX,V1,colour=V1)) p - p + stat_summary(fun.y=mean,geom=point) p - p + stat_summary(fun.y=mean,geom=line) p - p + stat_summary(fun.data=mean_cl_normal,conf.int = .99, geom=errorbar, width=0.2) Thanks, Mohan -Original Message- From: Radhakrishnan, Mohan (Cognizant) Sent: Wednesday, June 17, 2015 12:54 PM To: 'Dennis Murphy' Cc: r-help@r-project.org Subject: RE: [R] Error bars and CI Your sample code is working. But I am missing the logic when my dataset is involved. My full dataset is this. It is the V1 column I am interested in. I am not 'grouping' here. V1 IDX 1 0.796 1 2 0.542 2 3 0.510 3 4 0.617 4 5 0.482 5 6 0.387 6 7 0.272 7 8 0.536 8 9 0.498 9 10 0.402 10 11 0.328 11 12 0.542 12 13 0.299 13 14 0.647 14 15 0.291 15 16 0.815 16 17 0.680 17 18 0.363 18 19 0.560 19 20 0.334 20 Thanks, Mohan -Original Message- From: Dennis Murphy [mailto:djmu...@gmail.com] Sent: Tuesday, June 16, 2015 1:18 AM To: Radhakrishnan, Mohan (Cognizant) Subject: Re: [R] Error bars and CI Hi: Firstly, your dplyr code to generate the summary data frame is unnecessary and distracting, particularly since you didn't provide the input data set; you are asked to provide a *minimal* reproducible example, which you could easily have done with a built-in data set. That said, to get what I perceive you want, I used the InsectSprays data from the autoloaded datasets package. # Function to compute standard error of a mean sem - function(x) sqrt(var(x)/length(x)) ## Use insectSprays data for illustration ## Compute mean and SE of count for each level of spray library(dplyr) library(ggplot2) insectSumm - InsectSprays %% group_by(spray) %% summarise(mean = mean(count), se = sem(count)) # Since the x-variable is a factor, need to map group = 1 to # draw lines between factor levels. geom_pointrange() can be # used to produce the 99% CIs per factor level, geom_errorbar() # for the mean +/- SE. I ordered the geoms so that the errorbar # is last, but if you want it (mostly) overwritten, put the # geom_pointrange() call last. ggplot(insectSumm, aes(x = spray, y = mean)) + theme_bw() + geom_line(aes(group = 1), size = 1, color = darkorange) + geom_pointrange(aes(ymin = mean - qt(.995, 11) * se, ymax = mean + qt(.995, 11) * se), size = 1.5, color = firebrick) + geom_errorbar(aes(ymin = mean - se, ymax = mean + se), width = 0.2, size = 1) Clearly, you can pipe all the way through the ggplot() call, but I wanted to check the contents of the summary data frame first. Dennis On Mon, Jun 15, 2015 at 3:51 AM, mohan.radhakrish...@cognizant.com wrote: Hi, I want to plot a line graph using this data. IDX is x-axis and V1 is y-axis. I also want standard error bars and 99% CI to be shown. My code is given below. The section that plots the graph is the problem. I don't see all the points in the line graph with error bars. How can I also show the 99% CI in the graph ? V1 IDX 1 0.987 21 2 0.585 22 3 0.770 23 4 0.711 24 library(stringr) library(dplyr) library(ggplot2) data - read.table(D:\\jmh\\jmh.txt,sep=\t) final -data %% select(V1) %% filter(grepl(^Iteration, V1)) %% mutate(V1 = str_extract(V1, \\d+\\.\\d*)) final - mutate(final,IDX = 1:n()) jc - final %% filter(IDX 21) #Convert to numeric jc - data.frame(sapply(jc, function(x) as.numeric(as.character(x print(jc) # The following section is the problem. sem - function(x){ sd(x)/sqrt(length(x)) } meanvalue - apply(jc,2,mean) semvalue - apply(jc, 2, sem) mean_sem - data.frame(mean= meanvalue, sem= semvalue, group=names(jc)) #larger font theme_set(theme_gray(base_size = 20)) #plot using ggplot p - ggplot(mean_sem, aes(x=group, y=mean)) + geom_line(stat='identity') + geom_errorbar(aes(ymin=mean-sem, ymax=mean+sem), width=.2) print(p) Thanks, Mohan This e-mail and any files transmitted with it are for the sole use of the intended recipient(s) and may contain confidential and privileged information. If you are not the intended recipient(s), please reply to the sender and destroy all copies of the original message. Any unauthorized review, use, disclosure, dissemination, forwarding, printing or copying of this email, and/or any action taken in reliance on the contents of this e-mail is strictly prohibited and may be unlawful. Where permitted by applicable law, this e-mail and other e-mail communications sent to and from Cognizant e-mail addresses may be monitored. [[alternative HTML version deleted
[R] Error bars and CI
Hi, I want to plot a line graph using this data. IDX is x-axis and V1 is y-axis. I also want standard error bars and 99% CI to be shown. My code is given below. The section that plots the graph is the problem. I don't see all the points in the line graph with error bars. How can I also show the 99% CI in the graph ? V1 IDX 1 0.987 21 2 0.585 22 3 0.770 23 4 0.711 24 library(stringr) library(dplyr) library(ggplot2) data - read.table(D:\\jmh\\jmh.txt,sep=\t) final -data %% select(V1) %% filter(grepl(^Iteration, V1)) %% mutate(V1 = str_extract(V1, \\d+\\.\\d*)) final - mutate(final,IDX = 1:n()) jc - final %% filter(IDX 21) #Convert to numeric jc - data.frame(sapply(jc, function(x) as.numeric(as.character(x print(jc) # The following section is the problem. sem - function(x){ sd(x)/sqrt(length(x)) } meanvalue - apply(jc,2,mean) semvalue - apply(jc, 2, sem) mean_sem - data.frame(mean= meanvalue, sem= semvalue, group=names(jc)) #larger font theme_set(theme_gray(base_size = 20)) #plot using ggplot p - ggplot(mean_sem, aes(x=group, y=mean)) + geom_line(stat='identity') + geom_errorbar(aes(ymin=mean-sem, ymax=mean+sem), width=.2) print(p) Thanks, Mohan This e-mail and any files transmitted with it are for the sole use of the intended recipient(s) and may contain confidential and privileged information. If you are not the intended recipient(s), please reply to the sender and destroy all copies of the original message. Any unauthorized review, use, disclosure, dissemination, forwarding, printing or copying of this email, and/or any action taken in reliance on the contents of this e-mail is strictly prohibited and may be unlawful. Where permitted by applicable law, this e-mail and other e-mail communications sent to and from Cognizant e-mail addresses may be monitored. [[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] error bars
Hello R-help, Thanks to everyone for the prompt replies. Yes. I didn't reinstal the Hmisc package after updating R to the recent version. This worked. Thank you so, much! I'm relieved that I was able to update my charts just prior to my presentation. You'll are awesome. Best Regards, Franklin From: S Ellison [s.elli...@lgcgroup.com] Sent: Friday, October 26, 2012 4:48 AM To: Johnson, Franklin Theodore; r-help@R-project.org Subject: RE: error bars You have likely failed to install the required package or load the right library for the function you are trying to use. R 2.13 doesn't have an errbar function natively either, so there must have been such a package present in your R 2.13 installation. I have functions by that name in Hmisc and sfsmisc but I don't know whether either of those the one you were looking for; you'll have to go back to your code to see which library it used to load. S Ellison -Original Message- From: r-help-boun...@r-project.org [mailto:r-help-boun...@r-project.org] On Behalf Of Johnson, Franklin Theodore Sent: 25 October 2012 22:46 To: r-help@R-project.org Subject: [R] error bars Hello R-help, I am using R version 2.15.1. I upgraded from R version 2.13 a few months back. Previously, I was able to plot error bars on an xy scatter plot using the errbar function: errbar(RAEthylene$TIME,RAEthylene$AVE,RAEthylene$AVE+RAEthylen e$STD,RAEthylene$AVE-RAEthylene$STD,add = TRUE,lty=2,pch=17); Today, I went to update my plot. However, in R version 2.15.1 I get error code saying that this function cannot be found: Error: could not find function errbar I would perfer to avoid using the xy.error.bars-function(x, y, xbar, ybar) coding for these error bars, as I have many data to put on one plot. I've searched the .pdf file for R 2.15.1 version and cannot find any updates for this function. Do I have to reinstall version 2.13 again?? I need to generate these plots today!! Please advise. Regards, Franklin [[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. *** This email and any attachments are confidential. Any use...{{dropped:8}} __ 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] error bars
You have likely failed to install the required package or load the right library for the function you are trying to use. R 2.13 doesn't have an errbar function natively either, so there must have been such a package present in your R 2.13 installation. I have functions by that name in Hmisc and sfsmisc but I don't know whether either of those the one you were looking for; you'll have to go back to your code to see which library it used to load. S Ellison -Original Message- From: r-help-boun...@r-project.org [mailto:r-help-boun...@r-project.org] On Behalf Of Johnson, Franklin Theodore Sent: 25 October 2012 22:46 To: r-help@R-project.org Subject: [R] error bars Hello R-help, I am using R version 2.15.1. I upgraded from R version 2.13 a few months back. Previously, I was able to plot error bars on an xy scatter plot using the errbar function: errbar(RAEthylene$TIME,RAEthylene$AVE,RAEthylene$AVE+RAEthylen e$STD,RAEthylene$AVE-RAEthylene$STD,add = TRUE,lty=2,pch=17); Today, I went to update my plot. However, in R version 2.15.1 I get error code saying that this function cannot be found: Error: could not find function errbar I would perfer to avoid using the xy.error.bars-function(x, y, xbar, ybar) coding for these error bars, as I have many data to put on one plot. I've searched the .pdf file for R 2.15.1 version and cannot find any updates for this function. Do I have to reinstall version 2.13 again?? I need to generate these plots today!! Please advise. Regards, Franklin [[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. *** This email and any attachments are confidential. Any use...{{dropped:8}} __ 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] error bars
Hello R-help, I am using R version 2.15.1. I upgraded from R version 2.13 a few months back. Previously, I was able to plot error bars on an xy scatter plot using the errbar function: errbar(RAEthylene$TIME,RAEthylene$AVE,RAEthylene$AVE+RAEthylene$STD,RAEthylene$AVE-RAEthylene$STD,add = TRUE,lty=2,pch=17); Today, I went to update my plot. However, in R version 2.15.1 I get error code saying that this function cannot be found: Error: could not find function errbar I would perfer to avoid using the xy.error.bars-function(x, y, xbar, ybar) coding for these error bars, as I have many data to put on one plot. I've searched the .pdf file for R 2.15.1 version and cannot find any updates for this function. Do I have to reinstall version 2.13 again?? I need to generate these plots today!! Please advise. Regards, Franklin [[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] error bars
On Oct 25, 2012, at 2:45 PM, Johnson, Franklin Theodore wrote: Hello R-help, I am using R version 2.15.1. I upgraded from R version 2.13 a few months back. Previously, I was able to plot error bars on an xy scatter plot using the errbar function: errbar(RAEthylene$TIME,RAEthylene$AVE,RAEthylene$AVE+RAEthylene$STD,RAEthylene$AVE-RAEthylene$STD,add = TRUE,lty=2,pch=17); Today, I went to update my plot. However, in R version 2.15.1 I get error code saying that this function cannot be found: Error: could not find function errbar I would perfer to avoid using the xy.error.bars-function(x, y, xbar, ybar) coding for these error bars, as I have many data to put on one plot. I've searched the .pdf file for R 2.15.1 version and cannot find any updates for this function. Do I have to reinstall version 2.13 again?? There is no base::errbar function. You probably were using a package and have not yet reinstalled that package under the new version of R. When I run sos::findFn('errbar') I see two packages (Hmisc and sfsmisc) with a function of that name. -- David Winsemius, MD Alameda, CA, USA __ 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] error bars on line plot with error bars using ggplot
I'm new to this and struggling away with ggplot. I need to plot some line graphs for about 4 series. I have the values to plot and also the value of the standard error of the value. Is it possible to plot the standard error bars when the value are already calculated as opposed to letting R do the analysis to calculate the SE bars? Any simple example would be most appreciated. Thanks J - Dr. Jim Maas University of East Anglia [[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] error bars on line plot with error bars using ggplot
On Oct 3, 2012, at 6:41 AM, James Maas (MED) wrote: I'm new to this and struggling away with ggplot. I need to plot some line graphs for about 4 series. I have the values to plot and also the value of the standard error of the value. Is it possible to plot the standard error bars when the value are already calculated as opposed to letting R do the analysis to calculate the SE bars? The usual way to do that in base graphics is with the arrows function using an angle of 90. Any simple example would be most appreciated. Hey, that's _our_ line. Solutions extended when reproducible example provided. See the standard footer. -- David Winsemius, MD Alameda, CA, USA __ 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] error bars on line plot with error bars using ggplot
I'm new to this and struggling away with ggplot. I need to plot some line graphs for about 4 series. I have the values to plot and also the value of the standard error of the value. Is it possible to plot the standard error bars when the value are already calculated as opposed to letting R do the analysis to calculate the SE bars? Try googling 'error bars in ggplot' I found a useful description at http://wiki.stdout.org/rcookbook/Graphs/Plotting%20means%20and%20error%20bars%20%28ggplot2%29/ *** This email and any attachments are confidential. Any use...{{dropped:8}} __ 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] Error Bars ggplot2
How about this? Andpleasemakeusofthelargekeyatthebottomofyourkeyboard.Itmakescodemuchmorereadable. library(ggplot2) spd - factor(c(s,f,f,s,f,s,s,s,f,f,s,f)) r - c(4.9,3.2,2.1,.2,3.8,6.4,7.5,1.7,3.4,4.1,2.2,5) dataset - data.frame(spd, r) dataset - rbind(cbind(dataset, Type = DOE, delta = 2), cbind(dataset, Type = Non-DOE, delta = 3)) ggplot(dataset, aes(x = spd:factor(r), y = r, ymin = r - delta, ymax = r + delta, colour = spd, linetype = Type)) + geom_errorbar() + geom_point() ir. Thierry Onkelinx Instituut voor natuur- en bosonderzoek / Research Institute for Nature and Forest team Biometrie Kwaliteitszorg / team Biometrics Quality Assurance Kliniekstraat 25 1070 Anderlecht Belgium + 32 2 525 02 51 + 32 54 43 61 85 thierry.onkel...@inbo.be www.inbo.be To call in the statistician after the experiment is done may be no more than asking him to perform a post-mortem examination: he may be able to say what the experiment died of. ~ Sir Ronald Aylmer Fisher The plural of anecdote is not data. ~ Roger Brinner The combination of some data and an aching desire for an answer does not ensure that a reasonable answer can be extracted from a given body of data. ~ John Tukey -Oorspronkelijk bericht- Van: r-help-boun...@r-project.org [mailto:r-help-boun...@r-project.org] Namens Adam Gabbert Verzonden: donderdag 26 juli 2012 19:50 Aan: r-help@r-project.org Onderwerp: Re: [R] Error Bars ggplot2 Hi Dennis, Part of my problem could be that I'm unsure how to nest another variable withn spd.f. Perhaps if I give a better explanation of my goal things will make more sense. My intent is to calculate two sets of confidence intervals to show the benefits of a DOE approach versus a Non-DOE approach. For example, I want to calculate the confidence intervals for f and s in two ways. First using a DOE approach, by taking the mean of the f or s values plus/minus t-value at a 95%ci with 10df multiplied by the standard error [mean(f-values) +- tval(.95ci,10df)*std.err]. Second using a bin specific approach which only looks at the 6 f or s values (i.e, mean(f-values) +- tval(.95ci, 5df)*std.err.mean). This will leave me with two confidence intervals, that I want to plot side by side to show that the DOE approach confidence interval will be smaller for most cases. I have attached a sample plot that shows the plot layout I'm trying to get. Thanks AG Hi: Your code makes no sense because the variable by which you want to dodge is the same as the one you're using on the x-axis. Dodging by subgroups is an application of visualizing nested data, which you don't have (at least in the state that you posted). For your data, this would work: ggplot(data, aes(x = spd, y = r, colour = spd)) + geom_errorbar(aes(ymin = 3, ymax = 5), width = 0.1) + geom_point() I don't understand the point of the second geom_errorbar() call, so I'm just avoiding it. In order to dodge (appose groups in factor B side by side within each level of factor A), you need a third variable whose values are nested within levels of spd.f. HTH, Dennis On Thu, Jul 26, 2012 at 6:03 AM, Adam Gabbert adamjgabb...@gmail.com wrote: Hello, I'm attempting to plot error bars side by side rather than stacked on top of each other with ggplot2. Here is the sample code I am using: #Code #Data spd-c(s,f,f,s,f,s,s,s,f,f,s,f) r-c(4.9,3.2,2.1,.2,3.8,6.4,7.5,1.7,3.4,4.1,2.2,5) #Turn spd into a factor spd.f-factor(spd) #Place data into a data frame data-data.frame(cbind(spd.f,r)) #Load ggplot2 library(ggplot2) #Create plot pd-position_dodge(.2) myplot-ggplot(data,aes(x=spd,y=r,colour=spd))+ geom_errorbar(aes(ymin=3,ymax=5),width=.1)+ geom_point()+ geom_errorbar(aes(ymin=1,ymax=6),width=.1,colour=black,position=pd) #Display plot myplot I have attached a plot that my sample code produces. As you can see the error bars are stacked. How can I get them to plot side by side? Thanks AG * * * * * * * * * * * * * D I S C L A I M E R * * * * * * * * * * * * * Dit bericht en eventuele bijlagen geven enkel de visie van de schrijver weer en binden het INBO onder geen enkel beding, zolang dit bericht niet bevestigd is door een geldig ondertekend document. The views expressed in this message and any annex are purely those of the writer and may not be regarded as stating an official position of INBO, as long as the message is not confirmed by a duly signed document. __ 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] Error Bars ggplot2
Hello, I'm attempting to plot error bars side by side rather than stacked on top of each other with ggplot2. Here is the sample code I am using: #Code #Data spd-c(s,f,f,s,f,s,s,s,f,f,s,f) r-c(4.9,3.2,2.1,.2,3.8,6.4,7.5,1.7,3.4,4.1,2.2,5) #Turn spd into a factor spd.f-factor(spd) #Place data into a data frame data-data.frame(cbind(spd.f,r)) #Load ggplot2 library(ggplot2) #Create plot pd-position_dodge(.2) myplot-ggplot(data,aes(x=spd,y=r,colour=spd))+ geom_errorbar(aes(ymin=3,ymax=5),width=.1)+ geom_point()+ geom_errorbar(aes(ymin=1,ymax=6),width=.1,colour=black,position=pd) #Display plot myplot I have attached a plot that my sample code produces. As you can see the error bars are stacked. How can I get them to plot side by side? Thanks AG __ 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] Error Bars ggplot2
Is this what you mean? dat1 - data.frame( spd = c(s,f,f,s,f,s,s,s,f,f,s,f), r = c(4.9,3.2,2.1,.2,3.8,6.4,7.5,1.7,3.4,4.1,2.2,5)) myplot-ggplot(dat1, aes(spd, r, colour = spd)) + geom_errorbar(aes(ymin=3, ymax=5), width=.1) + geom_point() + coord_flip() John Kane Kingston ON Canada -Original Message- From: adamjgabb...@gmail.com Sent: Thu, 26 Jul 2012 09:03:44 -0400 To: r-help@r-project.org Subject: [R] Error Bars ggplot2 Hello, I'm attempting to plot error bars side by side rather than stacked on top of each other with ggplot2. Here is the sample code I am using: #Code #Data spd-c(s,f,f,s,f,s,s,s,f,f,s,f) r-c(4.9,3.2,2.1,.2,3.8,6.4,7.5,1.7,3.4,4.1,2.2,5) #Turn spd into a factor spd.f-factor(spd) #Place data into a data frame data-data.frame(cbind(spd.f,r)) #Load ggplot2 library(ggplot2) #Create plot pd-position_dodge(.2) myplot-ggplot(data,aes(x=spd,y=r,colour=spd))+ geom_errorbar(aes(ymin=3,ymax=5),width=.1)+ geom_point()+ geom_errorbar(aes(ymin=1,ymax=6),width=.1,colour=black,position=pd) #Display plot myplot I have attached a plot that my sample code produces. As you can see the error bars are stacked. How can I get them to plot side by side? Thanks AG __ 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. GET FREE 5GB EMAIL - Check out spam free email with many cool features! Visit http://www.inbox.com/email to find out more! __ 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] Error Bars ggplot2
Hi Dennis, Part of my problem could be that I'm unsure how to nest another variable withn spd.f. Perhaps if I give a better explanation of my goal things will make more sense. My intent is to calculate two sets of confidence intervals to show the benefits of a DOE approach versus a Non-DOE approach. For example, I want to calculate the confidence intervals for f and s in two ways. First using a DOE approach, by taking the mean of the f or s values plus/minus t-value at a 95%ci with 10df multiplied by the standard error [mean(f-values) +- tval(.95ci,10df)*std.err]. Second using a bin specific approach which only looks at the 6 f or s values (i.e, mean(f-values) +- tval(.95ci, 5df)*std.err.mean). This will leave me with two confidence intervals, that I want to plot side by side to show that the DOE approach confidence interval will be smaller for most cases. I have attached a sample plot that shows the plot layout I'm trying to get. Thanks AG Hi: Your code makes no sense because the variable by which you want to dodge is the same as the one you're using on the x-axis. Dodging by subgroups is an application of visualizing nested data, which you don't have (at least in the state that you posted). For your data, this would work: ggplot(data, aes(x = spd, y = r, colour = spd)) + geom_errorbar(aes(ymin = 3, ymax = 5), width = 0.1) + geom_point() I don't understand the point of the second geom_errorbar() call, so I'm just avoiding it. In order to dodge (appose groups in factor B side by side within each level of factor A), you need a third variable whose values are nested within levels of spd.f. HTH, Dennis On Thu, Jul 26, 2012 at 6:03 AM, Adam Gabbert adamjgabb...@gmail.com wrote: Hello, I'm attempting to plot error bars side by side rather than stacked on top of each other with ggplot2. Here is the sample code I am using: #Code #Data spd-c(s,f,f,s,f,s,s,s,f,f,s,f) r-c(4.9,3.2,2.1,.2,3.8,6.4,7.5,1.7,3.4,4.1,2.2,5) #Turn spd into a factor spd.f-factor(spd) #Place data into a data frame data-data.frame(cbind(spd.f,r)) #Load ggplot2 library(ggplot2) #Create plot pd-position_dodge(.2) myplot-ggplot(data,aes(x=spd,y=r,colour=spd))+ geom_errorbar(aes(ymin=3,ymax=5),width=.1)+ geom_point()+ geom_errorbar(aes(ymin=1,ymax=6),width=.1,colour=black,position=pd) #Display plot myplot I have attached a plot that my sample code produces. As you can see the error bars are stacked. How can I get them to plot side by side? Thanks AG __ 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] error bars for a barchart
Walmes, Thank you so much!!! I am still trying to understand all of your code but it works. I have changed it a bit so that I get upper and lower limits for the error bar, and that the origin starts at 0 so the negative values are plotted correctly. barchart(Change~fTreat,groups=Process,change, stderr=change$stderr, ylab=Pocertage change, xlab=Treatment, #ylim=-115:50, scales=list(alternating=FALSE, tick.number=7, tck=c(-1,0)), prepanel=function(y, stderr, subscripts=subscripts, ...){ uy - as.numeric(y+stderr[subscripts]) ly - as.numeric(y-stderr[subscripts]) list(ylim=range(y,uy,ly, finite=TRUE)) }, panel= function(x, y, subscripts, groups, stderr, box.ratio, ...){ panel.barchart(x, y, subscripts=subscripts, groups=groups, box.ratio=box.ratio,origin=0, ...) panel.abline(h=0,col=black,...) d - 1/(nlevels(groups)+nlevels(groups)/box.ratio) g - (as.numeric(groups[subscripts])-1); g - (g-median(g))*d panel.arrows(as.numeric(x)+g,y-stderr[subscripts], as.numeric(x)+g, y+stderr[subscripts], code=3,angle=90, length=0.025) } ) I am very new to creating function and would be great if you could explain what the d and g elemens actually do? this is just for me to understand and later maybe make my own functions. I am assuming that g centers the error bars? but d? Regards Beatriz de Francisco Mora PhD Student The Scottish Association for Marine Science Scottish Marine Institute Oban PA37 1QA Tel: 06131 559000 (switchboard) Fax: 01631559001 E. beatriz.defranci...@sams.ac.uk http://www.smi.ac.uk/beatriz-de-franciso From: r-help-boun...@r-project.org [r-help-boun...@r-project.org] on behalf of ilai [ke...@math.montana.edu] Sent: 02 May 2012 04:14 To: Walmes Zeviani Cc: r-help@r-project.org Subject: Re: [R] error bars for a barchart Thank you for your example. I only skimmed it, but since both solutions use nlevels and box.ratio it is no surprise we end up at the same place (although I do think your g-median is nicer than my 3/4). Thing is, I wouldn't call either of these simple... would be nice if one could just query the new centers, but I don't know if there is a way without hacking panel.barchart itself ? Cheers On Tue, May 1, 2012 at 1:34 PM, Walmes Zeviani walmeszevi...@gmail.com wrote: I have a repoducibe example here http://ridiculas.wordpress.com/2011/11/23/media-e-desvio-padrao-de-muitas-variaveis-separado-por-grupos/ Sorry for it be in Portuguese. Walmes. == Walmes Marques Zeviani LEG (Laboratório de Estatística e Geoinformação, 25.450418 S, 49.231759 W) Departamento de Estatística - Universidade Federal do Paraná fone: (+55) 41 3361 3573 VoIP: (3361 3600) 1053 1173 e-mail: wal...@ufpr.br twitter: @walmeszeviani homepage: http://www.leg.ufpr.br/~walmes linux user number: 531218 == __ 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. The Scottish Association for Marine Science (SAMS) is registered in Scotland as a Company Limited by Guarantee (SC009292) and is a registered charity (9206). SAMS has an actively trading wholly owned subsidiary company: SAMS Research Services Ltd a Limited Company (SC224404). All Companies in the group are registered in Scotland and share a registered office at Scottish Marine Institute, Oban Argyll PA37 1QA. The content of this message may contain personal views which are not the views of SAMS unless specifically stated. Please note that all email traffic is monitored for purposes of security and spam filtering. As such individual emails may be examined in more detail. __ 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] error bars for a barchart
Hi I have the following barchart to which I want to add error bars. library(lattice) barchart(Change~fTreat,groups=Process,change, auto.key=list(points=FALSE,rectangles=TRUE), panel=function(x, y,...){ panel.barchart(x,y,origin = 0,...); panel.abline(h=0,col=black,...); } ) I have tried using the panel.errbars from the memisc package which works great for xyplots, but when I add it to my code it does not respect the groups. library(memisc) barchart(cbind(Change,lower,upper)~fTreat,groups=Process,change, ylab=Pocertage change, ylim=-115:50, scales=list(alternating=FALSE, tick.number=7, tck=c(-1,0)), panel=function(x, y,groups,...){ panel.barchart(x,y=change$Change,groups=change$Process,origin = 0,...); panel.abline(h=0,col=black,...); panel.errbars(x,y,make.grid=none,ewidth=0.2,type=n,...) } ) Any ideas of how to add error bars to my plot either using the panel.errbars or any other function? The data: structure(list(Treat = structure(c(3L, 4L, 1L, 2L, 3L, 4L, 1L, 2L), .Label = c(12-380, 12-750, 8-380, 8-750), class = factor), Process = structure(c(1L, 1L, 1L, 1L, 2L, 2L, 2L, 2L), .Label = c(Resp, Cal), class = c(ordered, factor)), Change = c(-33.05, -34.74, 20.94, 18.06, 6.85, -28.57, -8.1, -78.72), upper = c(-13.22896628, -28.61149669, 31.29930461, 27.30173776, 39.73271282, 9.458372948, 13.11035572, -47.03745704), lower = c(-52.86120694, -40.87446411, 10.57421563, 8.822042178, -26.03144161, -66.60447035, -29.30563327, -110.3973761), fTreat = structure(c(1L, 2L, 3L, 4L, 1L, 2L, 3L, 4L), .Label = c(8-380, 8-750, 12-380, 12-750), class = c(ordered, factor))), .Names = c(Treat, Process, Change, upper, lower, fTreat), row.names = c(NA, -8L), class = data.frame) Regards Beatriz de Francisco Mora PhD Student The Scottish Association for Marine Science Scottish Marine Institute Oban PA37 1QA Tel: 06131 559000 (switchboard) Fax: 01631559001 E. beatriz.defranci...@sams.ac.ukmailto:beatriz.defranci...@sams.ac.uk http://www.smi.ac.uk/beatriz-de-franciso The Scottish Association for Marine Science (SAMS) is registered in Scotland as a Company Limited by Guarantee (SC009292) and is a registered charity (9206). SAMS has an actively trading wholly owned subsidiary company: SAMS Research Services Ltd a Limited Company (SC224404). All Companies in the group are registered in Scotland and share a registered office at Scottish Marine Institute, Oban Argyll PA37 1QA. The content of this message may contain personal views which are not the views of SAMS unless specifically stated. Please note that all email traffic is monitored for purposes of security and spam filtering. As such individual emails may be examined in more detail. [[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] error bars for a barchart
Hi I have the following barchart to which I want to add error bars. library(lattice) barchart(Change~fTreat,groups=Process,change, auto.key=list(points=FALSE,rectangles=TRUE), panel=function(x, y,...){ panel.barchart(x,y,origin = 0,...); panel.abline(h=0,col=black,...); } ) I have tried using the panel.errbars from the memisc package which works great for xyplots, but when I add it to my code it does not respect the groups. library(memisc) barchart(cbind(Change,lower,upper)~fTreat,groups=Process,change, ylab=Pocertage change, ylim=-115:50, scales=list(alternating=FALSE, tick.number=7, tck=c(-1,0)), panel=function(x, y,groups,...){ panel.barchart(x,y=change$Change,groups=change$Process,origin = 0,...); panel.abline(h=0,col=black,...); panel.errbars(x,y,make.grid=none,ewidth=0.2,type=n,...) } ) Any ideas of how to add error bars to my plot either using the panel.errbars or any other function? The data: structure(list(Treat = structure(c(3L, 4L, 1L, 2L, 3L, 4L, 1L, 2L), .Label = c(12-380, 12-750, 8-380, 8-750), class = factor), Process = structure(c(1L, 1L, 1L, 1L, 2L, 2L, 2L, 2L), .Label = c(Resp, Cal), class = c(ordered, factor)), Change = c(-33.05, -34.74, 20.94, 18.06, 6.85, -28.57, -8.1, -78.72), upper = c(-13.22896628, -28.61149669, 31.29930461, 27.30173776, 39.73271282, 9.458372948, 13.11035572, -47.03745704), lower = c(-52.86120694, -40.87446411, 10.57421563, 8.822042178, -26.03144161, -66.60447035, -29.30563327, -110.3973761), fTreat = structure(c(1L, 2L, 3L, 4L, 1L, 2L, 3L, 4L), .Label = c(8-380, 8-750, 12-380, 12-750), class = c(ordered, factor))), .Names = c(Treat, Process, Change, upper, lower, fTreat), row.names = c(NA, -8L), class = data.frame) Regards Beatriz de Francisco Mora PhD Student The Scottish Association for Marine Science Scottish Marine Institute Oban PA37 1QA Tel: 06131 559000 (switchboard) Fax: 01631559001 E. beatriz.defranci...@sams.ac.ukmailto:beatriz.defranci...@sams.ac.uk http://www.smi.ac.uk/beatriz-de-franciso The Scottish Association for Marine Science (SAMS) is registered in Scotland as a Company Limited by Guarantee (SC009292) and is a registered charity (9206). SAMS has an actively trading wholly owned subsidiary company: SAMS Research Services Ltd a Limited Company (SC224404). All Companies in the group are registered in Scotland and share a registered office at Scottish Marine Institute, Oban Argyll PA37 1QA. The content of this message may contain personal views which are not the views of SAMS unless specifically stated. Please note that all email traffic is monitored for purposes of security and spam filtering. As such individual emails may be examined in more detail. [[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] error bars for a barchart
Hi, I think the issue is not respecting the groups but finding the x-location of the center of bars in panel.barchart(groups,...). Don't know about the memisc package, but doesn't look like it provides an easy solution. This is how I do it: http://www.mail-archive.com/r-help@r-project.org/msg162299.html Might need to modify some for your data. HTH On Tue, May 1, 2012 at 8:01 AM, Beatriz De Francisco beatriz.defranci...@sams.ac.uk wrote: Hi I have the following barchart to which I want to add error bars. library(lattice) barchart(Change~fTreat,groups=Process,change, auto.key=list(points=FALSE,rectangles=TRUE), panel=function(x, y,...){ panel.barchart(x,y,origin = 0,...); panel.abline(h=0,col=black,...); } ) I have tried using the panel.errbars from the memisc package which works great for xyplots, but when I add it to my code it does not respect the groups. library(memisc) barchart(cbind(Change,lower,upper)~fTreat,groups=Process,change, ylab=Pocertage change, ylim=-115:50, scales=list(alternating=FALSE, tick.number=7, tck=c(-1,0)), panel=function(x, y,groups,...){ panel.barchart(x,y=change$Change,groups=change$Process,origin = 0,...); panel.abline(h=0,col=black,...); panel.errbars(x,y,make.grid=none,ewidth=0.2,type=n,...) } ) Any ideas of how to add error bars to my plot either using the panel.errbars or any other function? The data: structure(list(Treat = structure(c(3L, 4L, 1L, 2L, 3L, 4L, 1L, 2L), .Label = c(12-380, 12-750, 8-380, 8-750), class = factor), Process = structure(c(1L, 1L, 1L, 1L, 2L, 2L, 2L, 2L), .Label = c(Resp, Cal), class = c(ordered, factor)), Change = c(-33.05, -34.74, 20.94, 18.06, 6.85, -28.57, -8.1, -78.72), upper = c(-13.22896628, -28.61149669, 31.29930461, 27.30173776, 39.73271282, 9.458372948, 13.11035572, -47.03745704), lower = c(-52.86120694, -40.87446411, 10.57421563, 8.822042178, -26.03144161, -66.60447035, -29.30563327, -110.3973761), fTreat = structure(c(1L, 2L, 3L, 4L, 1L, 2L, 3L, 4L), .Label = c(8-380, 8-750, 12-380, 12-750), class = c(ordered, factor))), .Names = c(Treat, Process, Change, upper, lower, fTreat), row.names = c(NA, -8L), class = data.frame) Regards Beatriz de Francisco Mora PhD Student The Scottish Association for Marine Science Scottish Marine Institute Oban PA37 1QA Tel: 06131 559000 (switchboard) Fax: 01631559001 E. beatriz.defranci...@sams.ac.ukmailto:beatriz.defranci...@sams.ac.uk http://www.smi.ac.uk/beatriz-de-franciso The Scottish Association for Marine Science (SAMS) is registered in Scotland as a Company Limited by Guarantee (SC009292) and is a registered charity (9206). SAMS has an actively trading wholly owned subsidiary company: SAMS Research Services Ltd a Limited Company (SC224404). All Companies in the group are registered in Scotland and share a registered office at Scottish Marine Institute, Oban Argyll PA37 1QA. The content of this message may contain personal views which are not the views of SAMS unless specifically stated. Please note that all email traffic is monitored for purposes of security and spam filtering. As such individual emails may be examined in more detail. [[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.
Re: [R] error bars for a barchart
I have a repoducibe example here http://ridiculas.wordpress.com/2011/11/23/media-e-desvio-padrao-de-muitas-variaveis-separado-por-grupos/ Sorry for it be in Portuguese. Walmes. == Walmes Marques Zeviani LEG (Laboratório de Estatística e Geoinformação, 25.450418 S, 49.231759 W) Departamento de Estatística - Universidade Federal do Paraná fone: (+55) 41 3361 3573 VoIP: (3361 3600) 1053 1173 e-mail: wal...@ufpr.br twitter: @walmeszeviani homepage: http://www.leg.ufpr.br/~walmes linux user number: 531218 == [[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] error bars for a barchart
Thank you for your example. I only skimmed it, but since both solutions use nlevels and box.ratio it is no surprise we end up at the same place (although I do think your g-median is nicer than my 3/4). Thing is, I wouldn't call either of these simple... would be nice if one could just query the new centers, but I don't know if there is a way without hacking panel.barchart itself ? Cheers On Tue, May 1, 2012 at 1:34 PM, Walmes Zeviani walmeszevi...@gmail.com wrote: I have a repoducibe example here http://ridiculas.wordpress.com/2011/11/23/media-e-desvio-padrao-de-muitas-variaveis-separado-por-grupos/ Sorry for it be in Portuguese. Walmes. == Walmes Marques Zeviani LEG (Laboratório de Estatística e Geoinformação, 25.450418 S, 49.231759 W) Departamento de Estatística - Universidade Federal do Paraná fone: (+55) 41 3361 3573 VoIP: (3361 3600) 1053 1173 e-mail: wal...@ufpr.br twitter: @walmeszeviani homepage: http://www.leg.ufpr.br/~walmes linux user number: 531218 == __ 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] Error bars
Hi, Can anyone help with plotting vertical error bars on a bar graph. I have tried following examples online and in the big R book and writing my own function but I have been unsuccessful and donât really have an understanding of what it is I am doing. I have calculated my standard errors so basically just need to draw the bars on the graph but just donât have a clue!!! I donât even know what information people will need to help me.. The code for my graph is: barplot(tapply(Sporangia,list(Host,Isolate),mean),xlab=Isolate,ylab=Mean Sporangia per Needle,col=c(grey39,grey64,grey89),beside=T) col=c(grey39,grey64,grey89) legend(topright,inset=.05,title=Host,c(European Larch,Hybrid Larch,Japanese Larch),fill=col,horiz=FALSE) Any help would be greatly appreciated, Anna [[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] Error bars
You might try 'bargraph.CI' in R pkg 'sciplot'. ?bargraph.CI HTH, Savi Anna Harris annaharrisish...@hotmail.com 6/15/2011 1:00 PM Hi, Can anyone help with plotting vertical error bars on a bar graph. I have tried following examples online and in the big R book and writing my own function but I have been unsuccessful and don’t really have an understanding of what it is I am doing. I have calculated my standard errors so basically just need to draw the bars on the graph but just don’t have a clue!!! I don’t even know what information people will need to help me.. The code for my graph is: barplot(tapply(Sporangia,list(Host,Isolate),mean),xlab=Isolate,ylab=Mean Sporangia per Needle,col=c(grey39,grey64,grey89),beside=T) col=c(grey39,grey64,grey89) legend(topright,inset=.05,title=Host,c(European Larch,Hybrid Larch,Japanese Larch),fill=col,horiz=FALSE) Any help would be greatly appreciated, Anna [[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] Error bars in lattice barchart with groups
Henning Wildhagen wrote: i want to plot gene regulation data in a lattice barchart. To illustrate the problem i encounter, the following code uses the barleydataset: #No, i tried to add error bars using the following code: .. As Deepayan noted in # http://markmail.org/message/oljgimkav2qcdyre it's not easy without dissection barchart. The omission of bar charts with error bars is probably by design, because of the bad ink-to-info ratio. Nevertheless, I had to do it over and over, because big bosses love it because of the high ink content. ggplot provides a way out: http://had.co.nz/ggplot2/geom_errorbar.html Dieter -- View this message in context: http://r.789695.n4.nabble.com/Error-bars-in-lattice-barchart-with-groups-tp3065864p3066814.html Sent from the R help mailing list archive at Nabble.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] Error bars in lattice barchart with groups
This is an interesting discussion on barchart (without error bars) http://www.decisionsciencenews.com/2010/08/11/which-chart-is-better/ Dieter -- View this message in context: http://r.789695.n4.nabble.com/Error-bars-in-lattice-barchart-with-groups-tp3065864p3066860.html Sent from the R help mailing list archive at Nabble.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.
[R] Error bars in lattice barchart with groups
Dear R-users, i want to plot gene regulation data in a lattice barchart. To illustrate the problem i encounter, the following code uses the barleydataset: library(lattice) barley[[SD]] - 5 PLOT - barchart(data=barley, yield~variety|site, groups=year,origin=0, as.table=TRUE, scales=list(x=list(relation=same, rot=30), y=list(alternating=3,tck=-1)), col=c(grey,black), panel=function(...) { panel.grid(h=-1, v=0,col=darkgrey); panel.barchart(...,reference=FALSE)} ) PLOT #this works fine #No, i tried to add error bars using the following code: PLOT2 - barchart(data=barley, yield~variety|site, groups=year,origin=0, as.table=TRUE, scales=list(x=list(relation=same, rot=30), y=list(alternating=3,tck=-1)), col=c(grey,black), sd=barley$SD, prepanel=function(x,y,sd,subscripts,...){ ylim - list(ylim=c(min(y-sd[subscripts],na.rm=TRUE), max(y+sd[subscripts], na.rm=TRUE))) }, panel=function(x,y,subscripts,sd,...){ panel.grid(h = -1, v = 0,col=darkgrey) larrows(x0=x, y0=y, x1=x, y1=y-sd[subscripts],angle=90, code=2, length=0.075, ) larrows(x0=x, y0=y, x1=x, y1=y+sd[subscripts],angle=90, code=2, length=0.075, ) panel.barchart(x,y,subscripts=subscripts,reference=FALSE,...) }) PLOT2 The problem is that the error bars are not attached correctly to the bars. I searched for solutions in the mailing list and found some postings and proposed solutions, but i was not able to solve the problem. Thanks for any hints to get the error bars correctly attached to the columns. Greetings, Henning -- GRATIS! Movie-FLAT mit über 300 Videos. [[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] error bars in lattice barchart
Hi all, I've read the emails of Dan, Deepayan and Sundar about adding error bars to the lattice plots ( https://stat.ethz.ch/pipermail/r-help/2006-October/114883.html), but I still have the problem when I want to adding error bars to barchart. I tried both the solution of Deepayan and Sundar but without luck. Here is my code (I changed prepanel.ci and panel.ci a little to plot bars vertically): ## Sundar's solution ### prepanel.ci - function(x, y, ly, uy, subscripts, ...) { y - as.numeric(y) ly - as.numeric(ly[subscripts]) uy - as.numeric(uy[subscripts]) list(ylim = range(y, uy, ly, finite = TRUE)) } panel.ci - function(x, y, ly, uy, subscripts, groups = NULL, pch = 16, ...) { x - as.numeric(x) y - as.numeric(y) ly - as.numeric(ly[subscripts]) uy - as.numeric(uy[subscripts]) par - if(is.null(groups))plot.symbol else superpose.symbol sym - trellis.par.get(par) col - sym$col groups - if(!is.null(groups)) { groups[subscripts] } else { rep(1, along = x) } ug - unique(groups) for(i in seq(along = ug)) { subg - groups == ug[i] y.g - y[subg] x.g - x[subg] ly.g - ly[subg] uy.g - uy[subg] panel.abline(h = unique(y.g), col = grey) panel.arrows(ly.g, y.g, uy.g, y.g, col = 'black', length = 0.25, unit = native, angle = 90, code = 3) panel.barchart(x.g, y.g, pch = pch, col = col[i], ...) } } all = barchart( Score ~ Methods | Score.Name * RNA.Type, data = benchmark, box.ratio = 1.2, xlab = 'Methods', ylab = 'Percentage', groups = Seq.Number, layout = c(2, 5), # 2 columns per row between = list( y = 0.5, x = 0 ), # par.settings = list(fontsize=list(text=8)), ## specify the colors used for bars par.settings = list(fontsize=list(text=8), superpose.polygon = list(border = 'black', col = c('white', 'gray', 'black'))), par.strip.text = list(cex=0.9), auto.key = list(space = 'top', columns = 3, cex = 0.7), # key = key.variety, # index.cond = list(c('tRNA', '5S rRNA', 'SRP RNA', 'RNase P', '16S rRNA')), # index.cond = list(rep(1,6)), # ylim = my.ylim, scales = list(x = list(rot = 45), y=list(tck = 0.4, rot = 0, relation = 'free')), ly = benchmark$Score - benchmark$Error, uy = benchmark$Score + benchmark$Error, prepanel = prepanel.ci, panel.groups = panel.ci ) Deepayan's solution prepanel.ci - function(x, y, ly, uy, subscripts, ...) { y - as.numeric(y) ly - as.numeric(ly[subscripts]) uy - as.numeric(uy[subscripts]) list(ylim = range(y, uy, ly, finite = TRUE)) } panel.ci - function(x, y, ly, uy, subscripts, ...) { x - as.numeric(x) y - as.numeric(y) ly - as.numeric(ly[subscripts]) uy - as.numeric(uy[subscripts]) panel.barchart(x, y, ...) panel.arrows(x, ly, x, uy, col = 'black', length = 0.1, unit = native, angle = 90, code = 3) } all = barchart( Score ~ Methods | Score.Name * RNA.Type, data = benchmark, box.ratio = 1.2, xlab = 'Methods', ylab = 'Percentage', groups = Seq.Number, layout = c(2, 5), # 2 columns per row between = list( y = 0.5, x = 0 ), # par.settings = list(fontsize=list(text=8)), ## specify the colors used for bars par.settings = list(fontsize=list(text=8), superpose.polygon = list(border = 'black', col = c('white', 'gray', 'black'))), par.strip.text = list(cex=0.9), auto.key = list(space = 'top', columns = 3, cex = 0.7), # key = key.variety, # index.cond = list(c('tRNA', '5S rRNA', 'SRP RNA', 'RNase P', '16S rRNA')), # index.cond = list(rep(1,6)), # ylim = my.ylim, scales = list(x = list(rot = 45), y=list(tck = 0.4, rot = 0, relation = 'free')), ly = benchmark$Score - benchmark$Error, uy = benchmark$Score + benchmark$Error, prepanel = prepanel.ci, panel.groups = panel.ci, panel = panel.superpose ) Sundar's solution gives me the exact same original plot without error bars, and Deepayan's solution gives me a messy plot. Did I mess up anything in these two solutions? I'd appreciate any help from you experts. Thanks -- Best, Zhenjiang [[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] error bars on barplot
Hi I was hoping someone might be able to help me I have this data: birdid timetaken numvisits ptachchoice time bold 1087 810 1 AM0 108728 6 1 PM0 108713 3 2 AM0 1087 121 0 2 PM0 1046 121 0 1 AM1 1046 121 0 1 PM1 i've plotted the means like this: by(numvisits,patchchoice,summary) numvisits.means- by(numvisits,list(time=time,patchchoice=patchchoice),mean) numvisits.means barplot(numvisits.means,xlab=Patch Choice,ylab=Number of Visits,col=c(red,darkblue),beside=T,ylim=c(0,4)) labs-c(AM,PM) legend(1.09,3.98,labs,fill=cols) and need to add error bars, but i'm unsure as to how to do this. Thanks Sam [[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] error bars on barplot
On 04/09/2010 08:55 PM, Samantha Reynolds wrote: Hi I was hoping someone might be able to help me I have this data: birdid timetaken numvisits ptachchoice time bold 1087 810 1 AM0 108728 6 1 PM0 108713 3 2 AM0 1087 121 0 2 PM0 1046 121 0 1 AM1 1046 121 0 1 PM1 i've plotted the means like this: by(numvisits,patchchoice,summary) numvisits.means- by(numvisits,list(time=time,patchchoice=patchchoice),mean) numvisits.means barplot(numvisits.means,xlab=Patch Choice,ylab=Number of Visits,col=c(red,darkblue),beside=T,ylim=c(0,4)) labs-c(AM,PM) legend(1.09,3.98,labs,fill=cols) and need to add error bars, but i'm unsure as to how to do this. Hi Sam, Perhaps I should submit a FAQ on this one. Try: bar.err (agricolae) plotCI (gplots) xYplot (Hmisc) error.bars (psych) dispersion (plotrix) plotCI (plotrix) and there are probably others. Jim __ 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] error bars on barplot
Jim Lemon wrote: On 04/09/2010 08:55 PM, Samantha Reynolds wrote: Hi I was hoping someone might be able to help me I have this data: birdid timetaken numvisits ptachchoice time bold 1087 810 1 AM0 108728 6 1 PM0 108713 3 2 AM0 1087 121 0 2 PM0 1046 121 0 1 AM1 1046 121 0 1 PM1 i've plotted the means like this: by(numvisits,patchchoice,summary) numvisits.means- by(numvisits,list(time=time,patchchoice=patchchoice),mean) numvisits.means barplot(numvisits.means,xlab=Patch Choice,ylab=Number of Visits,col=c(red,darkblue),beside=T,ylim=c(0,4)) labs-c(AM,PM) legend(1.09,3.98,labs,fill=cols) and need to add error bars, but i'm unsure as to how to do this. Hi Sam, Perhaps I should submit a FAQ on this one. Try: bar.err (agricolae) plotCI (gplots) xYplot (Hmisc) error.bars (psych) dispersion (plotrix) plotCI (plotrix) and there are probably others. Jim geom_errorbar (ggplot2) Joh __ 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] error bars on barplot
bar.err (agricolae) plotCI (gplots) xYplot (Hmisc) error.bars (psych) dispersion (plotrix) plotCI (plotrix) Not to mention: http://biostat.mc.vanderbilt.edu/wiki/Main/DynamitePlots Hadley -- Assistant Professor / Dobelman Family Junior Chair Department of Statistics / Rice University http://had.co.nz/ __ 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] Error Bars in lattice- barcharts
Well, when the error message says argument 'lx' is missing, with no default, it really means that argument 'lx' is missing, with no default. Your panel function has an argument 'lx', which you forgot to change to 'ly' as you did with the prepanel function. Hope that helps... Thanks for the help Felix! It was a bit obvious what the problem was and I apologize for not thinking about the error message more clearly. I am going to continue this as I think that it would be helpful if there was a working example of this type of plot. Unfortunately, I do not have it yet. The modified example below produced a stacked barplot with lovely error bars. However, I can't seem to produce a plot that doesn't stack the bars. stack=FALSE doesn't seem to have any effect. Any thoughts? Thanks in advance. Sam #Generating the data library(lattice) temp - abs(rnorm(81*5)) err - as.data.frame(temp) err$section=c(down,down,down,mid,mid,mid, up,up, up) err$depth=c(Surface,D50, 2xD50) err$err.date=c(05/09/2009,12/09/2009,13/10/2009,19/10/2009,21/09/2009) err.split - with(err, split(temp, list(depth,section, err.date))) #I've tried to alter the panel function according to the thread to produce #vertical error bars in my barcharts prepanel.ci - function(x, y, ly, uy, subscripts, ...) { y - as.numeric(y) ly - as.numeric(ly[subscripts]) uy - as.numeric(uy[subscripts]) list(ylim = range(y, uy, ly, finite = TRUE)) } panel.ci - function(x, y, ly, uy, subscripts, pch = 16, ...) { x - as.numeric(x) y - as.numeric(y) ly - as.numeric(ly[subscripts]) uy - as.numeric(uy[subscripts]) panel.arrows(x, ly, x, uy, col = 'black', length = 0.25, unit = native, angle = 90, code = 3) panel.barchart(x, y, pch = pch, ...) } se -function(x) sqrt(var(x)/length(x)) err.ucl - sapply(err.split, function(x) { st - boxplot.stats(x) c(mean(x), mean(x) + se(x), mean(x) -se(x)) }) err.ucl - as.data.frame(t(err.ucl)) names(err.ucl) - c(mean, upper.se, lower.se) err.ucl$label - factor(rownames(err.ucl),levels = rownames(err.ucl)) # add factor, grouping and by variables err.ucl$section=c(down,down,down,mid,mid,mid, up,up, up) err.ucl$depth=c(Surface,D50, 2xD50) s err.ucl$err.date=c(05/09/2009,12/09/2009,13/10/2009,19/10/2009,21/09/2009) #This produces the figure I am looking for minus the error bars. with(err.ucl, barchart(mean ~ err.date | section, group=depth, layout=c(1,3), horizontal=FALSE, scales=list(x=list(rot=45)), )) #OK, now that this work and the error bars are drawn, I am curious why the stack=TRUE doesn't produce each bar beside each other. with(err.ucl, barchart(mean ~ err.date| section, group=depth, layout=c(1,3), horizontal=FALSE, stack=FALSE, scales=list(x=list(rot=45)), ly=lower.se, uy=upper.se, auto.key = list(points = FALSE, rectangles = TRUE, space= right, title = Depth, border = TRUE), #auto.key=TRUE, prepanel=prepanel.ci, panel=panel.superpose, panel.groups=panel.ci )) -- * Sam Albers Geography Program University of Northern British Columbia University Way Prince George, British Columbia Canada, V2N 4Z9 phone: 250 960-6777 * [[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] Error Bars in lattice- barcharts
Hi Sam and everybody, Can you educate me a little bit on the use of barchart? A command like this barchart(~table(someProperty), data=A) produces a barchart with horizontal bars. I want to produce that graph but with VERTICAL bars. clearly, horizontal=FALSE does not work. Thank you, Ivan sessionInfo() R version 2.10.0 (2009-10-26) x86_64-redhat-linux-gnu locale: [1] LC_CTYPE=en_US.UTF-8 LC_NUMERIC=C [3] LC_TIME=en_US.UTF-8LC_COLLATE=en_US.UTF-8 [5] LC_MONETARY=C LC_MESSAGES=en_US.UTF-8 [7] LC_PAPER=en_US.UTF-8 LC_NAME=C [9] LC_ADDRESS=C LC_TELEPHONE=C [11] LC_MEASUREMENT=en_US.UTF-8 LC_IDENTIFICATION=C attached base packages: [1] stats graphics grDevices utils datasets methods base other attached packages: [1] lattice_0.18-3 loaded via a namespace (and not attached): [1] grid_2.10.0 Ivan Gregoretti, PhD National Institute of Diabetes and Digestive and Kidney Diseases National Institutes of Health 5 Memorial Dr, Building 5, Room 205. Bethesda, MD 20892. USA. Phone: 1-301-496-1592 Fax: 1-301-496-9878 On Fri, Feb 19, 2010 at 7:22 PM, Sam Albers tonightstheni...@gmail.com wrote: Hello, I am attempting to write a script that adds error bars to a barchart. I basing my attempt heavily on the following thread: http://tolstoy.newcastle.edu.au/R/e2/help/06/10/2791.html I can't seem to get around the problem that was discussed in the thread. The following example should illustrate my problem. Sorry about the messy example but I am 1) trying to make it as close as possible to my actual work and 2) my skill level is spotty at best. Can anyone suggest a way to do this or even another way to make a grouped barchart with error bars? I'm not married to this method although I prefer working with lattice. Thanks for any help in advance! Sam #Generating the data library(lattice) temp - abs(rnorm(81*5)) err - as.data.frame(temp) err$section=c(down,down,down,mid,mid,mid, up,up, up) err$depth=c(Surface,D50, 2xD50) err$err.date=c(05/09/2009,05/09/2009,05/09/2009,05/09/2009,05/09/2009,05/09/2009,05/09/2009,05/09/2009,05/09/2009,05/10/2009,05/10/2009,05/10/2009,05/10/2009,05/10/2009,05/10/2009,05/10/2009,05/10/2009,05/10/2009,12/09/2009,12/09/2009,12/09/2009,12/09/2009,12/09/2009,12/09/2009,12/09/2009,12/09/2009,12/09/2009,13/10/2009,13/10/2009,13/10/2009,13/10/2009,13/10/2009,13/10/2009,13/10/2009,13/10/2009,13/10/2009,19/10/2009,19/10/2009,19/10/2009,19/10/2009,19/10/2009,19/10/2009,19/10/2009,19/10/2009,19/10/2009,21/09/2009,21/09/2009,21/09/2009,21/09/2009,21/09/2009,21/09/2009,21/09/2009,21/09/2009,21/09/2009,26/10/2009,26/10/2009,26/10/2009,26/10/2009,26/10/2009,26/10/2009,26/10/2009,26/10/2009,26/10/2009,27/09/2009,27/09/2009,27/09/2009,27/09/2009,27/09/2009,27/09/2009,27/09/2009,27/09/2009,27/09/2009,28/08/2009, 28/08/2009, 28/08/2009,28/08/2009, 28/08/2009, 28/08/2009,28/08/2009, 28/08/2009, 28/08/2009) err.split - with(err, split(temp, list(depth,section, err.date))) #I've tried to alter the panel function according to the thread to produce vertical error bars in my barcharts prepanel.ci - function(x, y, ly, uy, subscripts, ...) { y - as.numeric(y) ly - as.numeric(ly[subscripts]) uy - as.numeric(uy[subscripts]) list(ylim = range(y, uy, ly, finite = TRUE)) } panel.ci - function(x, y, lx, ux, subscripts, pch = 16, ...) { x - as.numeric(x) y - as.numeric(y) lx - as.numeric(lx[subscripts]) ux - as.numeric(ux[subscripts]) panel.arrows(x, ly, x, uy, col = 'black', length = 0.25, unit = native, angle = 90, code = 3) panel.barchart(x, y, pch = pch, ...) } se -function(x) sqrt(var(x)/length(x)) err.ucl - sapply(err.split, function(x) { st - boxplot.stats(x) c(mean(x), mean(x) + se(x), mean(x) -se(x)) }) err.ucl - as.data.frame(t(err.ucl)) names(err.ucl) - c(mean, upper.se, lower.se) err.ucl$label - factor(rownames(err.ucl),levels = rownames(err.ucl)) # add factor, grouping and by variables err.ucl$section=c(down,down,down,mid,mid,mid, up,up, up) err.ucl$depth=c(Surface,D50, 2xD50) #There has got to be a better way of doing this
Re: [R] Error Bars in lattice- barcharts
Hi Ivan, Can you educate me a little bit on the use of barchart? Unfortunately no... For this post I eventually used the barplot2() in the gplots packages. I got bogged down trying to do it in lattice so I looked for an alternative. It was quite straight forward which was nice and I was able to get what I wanted quite quickly. Sorry I can't be of more help. Sam [[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] Error Bars in lattice- barcharts
On 8 April 2010 06:03, Ivan Gregoretti ivang...@gmail.com wrote: Hi Sam and everybody, Can you educate me a little bit on the use of barchart? A command like this barchart(~table(someProperty), data=A) produces a barchart with horizontal bars. That should be barchart(table(someProperty), data=A) (the method for objects of class table) I want to produce that graph but with VERTICAL bars. clearly, horizontal=FALSE does not work. and you will find that horizontal = FALSE does work. -- Felix Andrews / 安福立 Postdoctoral Fellow Integrated Catchment Assessment and Management (iCAM) Centre Fenner School of Environment and Society [Bldg 48a] The Australian National University Canberra ACT 0200 Australia M: +61 410 400 963 T: + 61 2 6125 4670 E: felix.andr...@anu.edu.au CRICOS Provider No. 00120C -- http://www.neurofractal.org/felix/ __ 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] Error Bars in lattice- barcharts
On 20 February 2010 11:22, Sam Albers tonightstheni...@gmail.com wrote: #I've tried to alter the panel function according to the thread to produce vertical error bars in my barcharts prepanel.ci - function(x, y, ly, uy, subscripts, ...) { y - as.numeric(y) ly - as.numeric(ly[subscripts]) uy - as.numeric(uy[subscripts]) list(ylim = range(y, uy, ly, finite = TRUE)) } panel.ci - function(x, y, lx, ux, subscripts, pch = 16, ...) { x - as.numeric(x) y - as.numeric(y) lx - as.numeric(lx[subscripts]) ux - as.numeric(ux[subscripts]) panel.arrows(x, ly, x, uy, col = 'black', length = 0.25, unit = native, angle = 90, code = 3) panel.barchart(x, y, pch = pch, ...) } # Deepayan's original example. I am unsure how to diagnose the packet error. This is where I run into problems Well, when the error message says argument 'lx' is missing, with no default, it really means that argument 'lx' is missing, with no default. Your panel function has an argument 'lx', which you forgot to change to 'ly' as you did with the prepanel function. Hope that helps... with(err.ucl, barchart(mean ~ err.date | section, group=depth, layout=c(1,3), horizontal=FALSE, scales=list(x=list(rot=45)), ly=lower.se, uy=upper.se, prepanel=prepanel.ci, panel=panel.superpose, panel.groups=panel.ci )) -- Felix Andrews / 安福立 Postdoctoral Fellow Integrated Catchment Assessment and Management (iCAM) Centre Fenner School of Environment and Society [Bldg 48a] The Australian National University Canberra ACT 0200 Australia M: +61 410 400 963 T: + 61 2 6125 4670 E: felix.andr...@anu.edu.au CRICOS Provider No. 00120C -- http://www.neurofractal.org/felix/ __ 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] error bars
Dear friends, I have a statistical question. Sometimes, if I compare boys to girls on a specific variable, the error bars (confidence interval of means) seem to overlap slightly. Still, when I run a t-test, I find statistically significant differences. The rule is clear: if the confidence intervals do not overlap, then there is statistically significant difference. But if they overlap slightly, we have to use a t-test to know for sure if the the two means differ significantly. The point is: is there a rule of thumb to say, for example, if the overlap is less than 20% of the length of the standard error, then a t-test would give significant results? thank you for your time P.S.1 is there an easy way to plot error bars in R? P.S.2 an interesting discussion about this - highly recommended to read it - can be found at http://scienceblogs.com/cognitivedaily/2007/03/ill_bet_you_dont_understand_er.php jason Dr. Iasonas Lamprianou Assistant Professor (Educational Research and Evaluation) Department of Education Sciences European University-Cyprus P.O. Box 22006 1516 Nicosia Cyprus Tel.: +357-22-713178 Fax: +357-22-590539 Honorary Research Fellow Department of Education The University of Manchester Oxford Road, Manchester M13 9PL, UK Tel. 0044 161 275 3485 iasonas.lampria...@manchester.ac.uk __ 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] error bars
you can write a function for yourself using arrows: #x,y: dataset as vectors #xe,ye: errors per entry as vectors, if the errors are symmetric arrbar-function(x,y,xe,ye){ l-length(x) for (i in 1:l) { arrows(x[i],y[i],x[i]-xe[i]/2,y[i],angle=90,length=0.05) arrows(x[i],y[i],x[i]+xe[i]/2,y[i],angle=90,length=0.05) arrows(x[i],y[i],x[i],y[i]-ye[i]/2,angle=90,length=0.05) arrows(x[i],y[i],x[i],y[i]+ye[i]/2,angle=90,length=0.05) } } Iasonas Lamprianou schrieb: Dear friends, I have a statistical question. Sometimes, if I compare boys to girls on a specific variable, the error bars (confidence interval of means) seem to overlap slightly. Still, when I run a t-test, I find statistically significant differences. The rule is clear: if the confidence intervals do not overlap, then there is statistically significant difference. But if they overlap slightly, we have to use a t-test to know for sure if the the two means differ significantly. The point is: is there a rule of thumb to say, for example, if the overlap is less than 20% of the length of the standard error, then a t-test would give significant results? thank you for your time P.S.1 is there an easy way to plot error bars in R? P.S.2 an interesting discussion about this - highly recommended to read it - can be found at http://scienceblogs.com/cognitivedaily/2007/03/ill_bet_you_dont_understand_er.php jason Dr. Iasonas Lamprianou Assistant Professor (Educational Research and Evaluation) Department of Education Sciences European University-Cyprus P.O. Box 22006 1516 Nicosia Cyprus Tel.: +357-22-713178 Fax: +357-22-590539 Honorary Research Fellow Department of Education The University of Manchester Oxford Road, Manchester M13 9PL, UK Tel. 0044 161 275 3485 iasonas.lampria...@manchester.ac.uk __ 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. -- ___ Dipl.-Phys. Markus Schmotz Universität Konstanz Fachbereich Physik, Lehrstuhl Leiderer Postfach M 676 D-78457 Konstanz Tel.: +49 7531 88 3803, Fax: 3127 Mail: markus.schm...@uni-konstanz.de __ 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] error bars
Iasonas, In response to PS.1 try error.bars in the psych package. Bill At 1:04 AM -0700 3/30/10, Iasonas Lamprianou wrote: Dear friends, I have a statistical question. Sometimes, if I compare boys to girls on a specific variable, the error bars (confidence interval of means) seem to overlap slightly. Still, when I run a t-test, I find statistically significant differences. The rule is clear: if the confidence intervals do not overlap, then there is statistically significant difference. But if they overlap slightly, we have to use a t-test to know for sure if the the two means differ significantly. The point is: is there a rule of thumb to say, for example, if the overlap is less than 20% of the length of the standard error, then a t-test would give significant results? thank you for your time P.S.1 is there an easy way to plot error bars in R? P.S.2 an interesting discussion about this - highly recommended to read it - can be found at http://scienceblogs.com/cognitivedaily/2007/03/ill_bet_you_dont_understand_er.php jason Dr. Iasonas Lamprianou Assistant Professor (Educational Research and Evaluation) Department of Education Sciences European University-Cyprus P.O. Box 22006 1516 Nicosia Cyprus Tel.: +357-22-713178 Fax: +357-22-590539 Honorary Research Fellow Department of Education The University of Manchester Oxford Road, Manchester M13 9PL, UK Tel. 0044 161 275 3485 iasonas.lampria...@manchester.ac.uk __ 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. -- William Revelle http://revelle.net/revelle.html 2815 Lakeside Court http://revelle.net/lakeside Evanston, Illinois It is 6 minutes to midnight http://www.thebulletin.org __ 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] error bars
thank you Dr. Iasonas Lamprianou Assistant Professor (Educational Research and Evaluation) Department of Education Sciences European University-Cyprus P.O. Box 22006 1516 Nicosia Cyprus Tel.: +357-22-713178 Fax: +357-22-590539 Honorary Research Fellow Department of Education The University of Manchester Oxford Road, Manchester M13 9PL, UK Tel. 0044 161 275 3485 iasonas.lampria...@manchester.ac.uk --- On Tue, 30/3/10, William Revelle li...@revelle.net wrote: From: William Revelle li...@revelle.net Subject: Re: [R] error bars To: Iasonas Lamprianou lampria...@yahoo.com, r-help@r-project.org Date: Tuesday, 30 March, 2010, 13:56 Iasonas, In response to PS.1 try error.bars in the psych package. Bill At 1:04 AM -0700 3/30/10, Iasonas Lamprianou wrote: Dear friends, I have a statistical question. Sometimes, if I compare boys to girls on a specific variable, the error bars (confidence interval of means) seem to overlap slightly. Still, when I run a t-test, I find statistically significant differences. The rule is clear: if the confidence intervals do not overlap, then there is statistically significant difference. But if they overlap slightly, we have to use a t-test to know for sure if the the two means differ significantly. The point is: is there a rule of thumb to say, for example, if the overlap is less than 20% of the length of the standard error, then a t-test would give significant results? thank you for your time P.S.1 is there an easy way to plot error bars in R? P.S.2 an interesting discussion about this - highly recommended to read it - can be found at http://scienceblogs.com/cognitivedaily/2007/03/ill_bet_you_dont_understand_er.php jason Dr. Iasonas Lamprianou Assistant Professor (Educational Research and Evaluation) Department of Education Sciences European University-Cyprus P.O. Box 22006 1516 Nicosia Cyprus Tel.: +357-22-713178 Fax: +357-22-590539 Honorary Research Fellow Department of Education The University of Manchester Oxford Road, Manchester M13 9PL, UK Tel. 0044 161 275 3485 iasonas.lampria...@manchester.ac.uk __ 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. -- William Revelle http://revelle.net/revelle.html 2815 Lakeside Court http://revelle.net/lakeside Evanston, Illinois It is 6 minutes to midnight http://www.thebulletin.org __ 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] Error Bars in lattice- barcharts
Hello, I am attempting to write a script that adds error bars to a barchart. I basing my attempt heavily on the following thread: http://tolstoy.newcastle.edu.au/R/e2/help/06/10/2791.html I can't seem to get around the problem that was discussed in the thread. The following example should illustrate my problem. Sorry about the messy example but I am 1) trying to make it as close as possible to my actual work and 2) my skill level is spotty at best. Can anyone suggest a way to do this or even another way to make a grouped barchart with error bars? I'm not married to this method although I prefer working with lattice. Thanks for any help in advance! Sam #Generating the data library(lattice) temp - abs(rnorm(81*5)) err - as.data.frame(temp) err$section=c(down,down,down,mid,mid,mid, up,up, up) err$depth=c(Surface,D50, 2xD50) err$err.date=c(05/09/2009,05/09/2009,05/09/2009,05/09/2009,05/09/2009,05/09/2009,05/09/2009,05/09/2009,05/09/2009,05/10/2009,05/10/2009,05/10/2009,05/10/2009,05/10/2009,05/10/2009,05/10/2009,05/10/2009,05/10/2009,12/09/2009,12/09/2009,12/09/2009,12/09/2009,12/09/2009,12/09/2009,12/09/2009,12/09/2009,12/09/2009,13/10/2009,13/10/2009,13/10/2009,13/10/2009,13/10/2009,13/10/2009,13/10/2009,13/10/2009,13/10/2009,19/10/2009,19/10/2009,19/10/2009,19/10/2009,19/10/2009,19/10/2009,19/10/2009,19/10/2009,19/10/2009,21/09/2009,21/09/2009,21/09/2009,21/09/2009,21/09/2009,21/09/2009,21/09/2009,21/09/2009,21/09/2009,26/10/2009,26/10/2009,26/10/2009,26/10/2009,26/10/2009,26/10/2009,26/10/2009,26/10/2009,26/10/2009,27/09/2009,27/09/2009,27/09/2009,27/09/2009,27/09/2009,27/09/2009,27/09/2009,27/09/2009,27/09/2009,28/08/2009, 28/08/2009, 28/08/2009,28/08/2009, 28/08/2009, 28/08/2009,28/08/2009, 28/08/2009, 28/08/2009) err.split - with(err, split(temp, list(depth,section, err.date))) #I've tried to alter the panel function according to the thread to produce vertical error bars in my barcharts prepanel.ci - function(x, y, ly, uy, subscripts, ...) { y - as.numeric(y) ly - as.numeric(ly[subscripts]) uy - as.numeric(uy[subscripts]) list(ylim = range(y, uy, ly, finite = TRUE)) } panel.ci - function(x, y, lx, ux, subscripts, pch = 16, ...) { x - as.numeric(x) y - as.numeric(y) lx - as.numeric(lx[subscripts]) ux - as.numeric(ux[subscripts]) panel.arrows(x, ly, x, uy, col = 'black', length = 0.25, unit = native, angle = 90, code = 3) panel.barchart(x, y, pch = pch, ...) } se -function(x) sqrt(var(x)/length(x)) err.ucl - sapply(err.split, function(x) { st - boxplot.stats(x) c(mean(x), mean(x) + se(x), mean(x) -se(x)) }) err.ucl - as.data.frame(t(err.ucl)) names(err.ucl) - c(mean, upper.se, lower.se) err.ucl$label - factor(rownames(err.ucl),levels = rownames(err.ucl)) # add factor, grouping and by variables err.ucl$section=c(down,down,down,mid,mid,mid, up,up, up) err.ucl$depth=c(Surface,D50, 2xD50) #There has got to be a better way of doing this err.ucl$err.date=c(05/09/2009,05/09/2009,05/09/2009,05/09/2009,05/09/2009,05/09/2009,05/09/2009,05/09/2009,05/09/2009,05/10/2009,05/10/2009,05/10/2009,05/10/2009,05/10/2009,05/10/2009,05/10/2009,05/10/2009,05/10/2009,12/09/2009,12/09/2009,12/09/2009,12/09/2009,12/09/2009,12/09/2009,12/09/2009,12/09/2009,12/09/2009,13/10/2009,13/10/2009,13/10/2009,13/10/2009,13/10/2009,13/10/2009,13/10/2009,13/10/2009,13/10/2009,19/10/2009,19/10/2009,19/10/2009,19/10/2009,19/10/2009,19/10/2009,19/10/2009,19/10/2009,19/10/2009,21/09/2009,21/09/2009,21/09/2009,21/09/2009,21/09/2009,21/09/2009,21/09/2009,21/09/2009,21/09/2009,26/10/2009,26/10/2009,26/10/2009,26/10/2009,26/10/2009,26/10/2009,26/10/2009,26/10/2009,26/10/2009,27/09/2009,27/09/2009,27/09/2009,27/09/2009,27/09/2009,27/09/2009,27/09/2009,27/09/2009,27/09/2009,28/08/2009, 28/08/2009, 28/08/2009,28/08/2009, 28/08/2009, 28/08/2009,28/08/2009, 28/08/2009, 28/08/2009) #This produces the figure I am looking for minus the error bars. with(err.ucl, barchart(mean ~ err.date | section, group=depth, layout=c(1,3), horizontal=FALSE, scales=list(x=list(rot=45)), )) # Deepayan's original example. I am unsure how to diagnose the packet error. This is where I run into problems with(err.ucl, barchart(mean ~ err.date | section, group=depth, layout=c(1,3), horizontal=FALSE, scales=list(x=list(rot=45)), ly=lower.se, uy=upper.se, prepanel=prepanel.ci, panel=panel.superpose, panel.groups=panel.ci )) -- * Sam Albers Geography Program University of Northern British Columbia University Way Prince George, British Columbia Canada, V2N 4Z9 phone: 250 960-6777 * [[alternative HTML version deleted]]
[R] Error bars on barplots for only particular bars
Hi, I have a data set that has columns bird.species, tree.speciesand count. I am investigating differences in tree species usge by two species of birds. Count is numerical and is a count of observations of bird species x using tree species x. For bird species A I have 3 different counts for each tree species. For bird species B I have only 1 count for each tree species. I have generated a barplot using the following function: barplot(tapply(count,list(bird.species,tree.species),mean),beside=TRUE) This graph is so far ok and gives the mean count for bird species A. I want to add error bars to illustrate the variance in mean of bird species A for each tree species. The error bar function I am using is: error.bars-function(yv,z,nn){ xv-barplot(yv,ylim=c(0,(max(yv)+max(z))),names=nn, ylab=deparse(substitute(yv))) g-(max(xv)-min(xv))/50 for (i in 1:length(xv)){lines(c(xv[i],xv[i]),c(yv[i]+z[i],yv[i]-z[i])) lines(c(xv[i]-g,xv[i]+g),c(yv[i]+z[i],yv[i]+z[i])) lines(c(xv[i]-g,xv[i]+g),c(yv[i]-z[i],yv[i]-z[i]))}} I used error.bars(ybar1,se1,labels1) to try generate the error bars with se1-rep(standard error of a mean, no. of numbers used to calculate mean) labels1-as.character(levels(tree.species)) ybar1-as.vector(tapply(count,tree.species,mean)) but the it failed and the resulting warning I got was: Error in barplot.default(yv, ylim = c(0, (max(yv) + max(z))), names = nn, : incorrect number of names I was wondering If anyone could help with me this warning, or point me in the right direction as to how to illustrate the variance in means from bird species A without adding any error bars to bird species B (which has no variance to show)? Any help is very much appreciated, Thanks, Seán Kelly. -- View this message in context: http://n4.nabble.com/Error-bars-on-barplots-for-only-particular-bars-tp1014284p1014284.html Sent from the R help mailing list archive at Nabble.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] Error bars on barplots for only particular bars
On 01/15/2010 08:43 AM, kellys17 wrote: Hi, I have a data set that has columns bird.species, tree.speciesand count. I am investigating differences in tree species usge by two species of birds. Count is numerical and is a count of observations of bird species x using tree species x. For bird species A I have 3 different counts for each tree species. For bird species B I have only 1 count for each tree species. I have generated a barplot using the following function: barplot(tapply(count,list(bird.species,tree.species),mean),beside=TRUE) This graph is so far ok and gives the mean count for bird species A. I want to add error bars to illustrate the variance in mean of bird species A for each tree species. The error bar function I am using is: error.bars-function(yv,z,nn){ xv-barplot(yv,ylim=c(0,(max(yv)+max(z))),names=nn, ylab=deparse(substitute(yv))) g-(max(xv)-min(xv))/50 for (i in 1:length(xv)){lines(c(xv[i],xv[i]),c(yv[i]+z[i],yv[i]-z[i])) lines(c(xv[i]-g,xv[i]+g),c(yv[i]+z[i],yv[i]+z[i])) lines(c(xv[i]-g,xv[i]+g),c(yv[i]-z[i],yv[i]-z[i]))}} I used error.bars(ybar1,se1,labels1) to try generate the error bars with se1-rep(standard error of a mean, no. of numbers used to calculate mean) labels1-as.character(levels(tree.species)) ybar1-as.vector(tapply(count,tree.species,mean)) but the it failed and the resulting warning I got was: Error in barplot.default(yv, ylim = c(0, (max(yv) + max(z))), names = nn, : incorrect number of names I was wondering If anyone could help with me this warning, or point me in the right direction as to how to illustrate the variance in means from bird species A without adding any error bars to bird species B (which has no variance to show)? Hi Sean, The easiest way I can think of is to add a test to your error bar drawing routine so that it does nothing when the variance is NA: for(i in 1:length(xv)) { if(!is.na(z[i])) { lines... } } However, the error is about the number of names not being equal to the number of heights, so you will have to make sure that is fixed, too. Jim __ 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] error bars in matplot
Tim Smith wrote: Hi, I was trying to get error bars in my matplot. I looked at an earlier thread, and the sample code that I made is: #-- library(plotrix) mat1 - matrix(sample(1:30,10),nrow=5,ncol=2) ses - matrix(sample(1:3,10,replace=T),nrow=5,ncol=2) vect - seq(20,100,20) rownames(mat1) - rownames(ses) - vect colnames(mat1) - colnames(ses) - letters[1:2] matplot(mat1,pch=c('x','o'),type = b,lwd = 2,lty = c(1,2), col = c(green,black),cex.main = 1.8,cex=2,cex.lab=1.5, main = Graph 1,xlab = Numbers 1,ylab = Numbers 2,cex.axis = 1.6,axes=F) plotCI(rep(vect,2),mat1,ses2,pch=NA,add=T, col=rep(c(green,black),each=nrow(mat1))) axis(1,1:5,labels = vect,cex.axis=1.5) axis(2,cex.axis=1.5) #-- I don't get the error bars though. If I set 'add = F' in plotCI function, then I can see the error bars, but they just can't be added to the matplot. What am I doing wrong? Is there any other way to get the error bars? Hi Tim, Try the dispersion function in plotrix to add error bars. You will probably have to add ylim=c(0,29) to your matplot command. dispersion(rep(1:5,2),mat1,ses) Jim __ 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] error bars in matplot
Thanks Mathieu and Jim, That worked! From: Jim Lemon j...@bitwrit.com.au Cc: r r-h...@stat.math.ethz.ch Sent: Friday, April 17, 2009 7:45:39 AM Subject: Re: [R] error bars in matplot Tim Smith wrote: Hi, I was trying to get error bars in my matplot. I looked at an earlier thread, and the sample code that I made is: #-- library(plotrix) mat1 - matrix(sample(1:30,10),nrow=5,ncol=2) ses - matrix(sample(1:3,10,replace=T),nrow=5,ncol=2) vect - seq(20,100,20) rownames(mat1) - rownames(ses) - vect colnames(mat1) - colnames(ses) - letters[1:2] matplot(mat1,pch=c('x','o'),type = b,lwd = 2,lty = c(1,2), col = c(green,black),cex.main = 1.8,cex=2,cex.lab=1.5, main = Graph 1,xlab = Numbers 1,ylab = Numbers 2,cex.axis = 1.6,axes=F) plotCI(rep(vect,2),mat1,ses2,pch=NA,add=T, col=rep(c(green,black),each=nrow(mat1))) axis(1,1:5,labels = vect,cex.axis=1.5) axis(2,cex.axis=1.5) #-- I don't get the error bars though. If I set 'add = F' in plotCI function, then I can see the error bars, but they just can't be added to the matplot. What am I doing wrong? Is there any other way to get the error bars? Hi Tim, Try the dispersion function in plotrix to add error bars. You will probably have to add ylim=c(0,29) to your matplot command. dispersion(rep(1:5,2),mat1,ses) Jim [[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] error bars in matplot
Hi, I was trying to get error bars in my matplot. I looked at an earlier thread, and the sample code that I made is: #-- library(plotrix) mat1 - matrix(sample(1:30,10),nrow=5,ncol=2) ses - matrix(sample(1:3,10,replace=T),nrow=5,ncol=2) vect - seq(20,100,20) rownames(mat1) - rownames(ses) - vect colnames(mat1) - colnames(ses) - letters[1:2] matplot(mat1,pch=c('x','o'),type = b,lwd = 2,lty = c(1,2), col = c(green,black),cex.main = 1.8,cex=2,cex.lab=1.5, main = Graph 1,xlab = Numbers 1,ylab = Numbers 2,cex.axis = 1.6,axes=F) plotCI(rep(vect,2),mat1,ses2,pch=NA,add=T, col=rep(c(green,black),each=nrow(mat1))) axis(1,1:5,labels = vect,cex.axis=1.5) axis(2,cex.axis=1.5) #-- I don't get the error bars though. If I set 'add = F' in plotCI function, then I can see the error bars, but they just can't be added to the matplot. What am I doing wrong? Is there any other way to get the error bars? thanks! [[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] error bars in matplot
Hi Tim, there are a couple of problems in your example. (1) The most important is that your 'x' values for the matplot are 1:5 (that is row numbers of your mat1 matrix) and are seq(20,100,20) (that is, your vect vector) for your error bars. Error bars are thus plotted outside the plotting area ... (2) the ses2 variable is not defined in your example. I thus modified your code accordingly : library(plotrix) mat1 - matrix(sample(1:30,10),nrow=5,ncol=2) ses - sample(1:3,10,replace=T) vect - seq(20,100,20) rownames(mat1) - rownames(ses) - vect colnames(mat1) - colnames(ses) - letters[1:2] # I added the vect vector as 'x' values. # No more need to define the axes # Just supressed the box around the plot with bty='n' # to fit the look of your original plot matplot(x=vect, y=mat1, pch=c('x','o'), type = b, lwd = 2, lty = c(1,2), col = c(green,black), main = Graph 1, xlab = Numbers 1, ylab = Numbers 2, cex.main = 1.8, cex=2, cex.lab=1.5, cex.axis = 1.6, bty='n') # I changed ses2 to ses and matrices to vectors plotCI(x=rep(vect,2), y= as.vector(mat1), uiw=as.vector(ses), col=rep(c(green,black),each=nrow(mat1)), add=T) HTH, Matthieu __ 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] error bars
On Thu, Feb 19, 2009 at 1:19 AM, jdeisenberg catc...@catcode.com wrote: Nicole Hackman wrote: Hello, I have a very simple data set i imported from excel including 96 averages in a column along with 96 standard errors associated with those averages (calculated in excel). I plotted the 95 averages using r and I am wondering if it is possible to plot the second column of standard errors while applying error bars to each value so they represent the error corresponding to each average? You might also find http://users.fmg.uva.nl/rgrasman/rpages/2005/09/error-bars-in-plots.html this page to be useful; it doesn't require you to load any new packages. On the other hand, it's a fundamentally limited approach. With a small investment in learning ggplot2, you can easily add error bars to absolutely any type of graphic. Hadley -- http://had.co.nz/ __ 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] error bars
Hello, I have a very simple data set i imported from excel including 96 averages in a column along with 96 standard errors associated with those averages (calculated in excel). I plotted the 95 averages using r and I am wondering if it is possible to plot the second column of standard errors while applying error bars to each value so they represent the error corresponding to each average? thanks, Nicole -- Nicole Hackman Master of Science Student University of Washington College of Forest Resources Box 352100 n...@u.washington.edu [[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] error bars
Check out ggplot2: http://had.co.nz/ggplot2/ Particularly: http://had.co.nz/ggplot2/geom_errorbar.html If you need more help you'll have to provide a self-contained set of data/code. Hopefully you'll soon be completely rid of this strange excel of which you speak :Op On Wed, Feb 18, 2009 at 9:38 PM, Nicole Hackman nicole.hack...@gmail.com wrote: Hello, I have a very simple data set i imported from excel including 96 averages in a column along with 96 standard errors associated with those averages (calculated in excel). I plotted the 95 averages using r and I am wondering if it is possible to plot the second column of standard errors while applying error bars to each value so they represent the error corresponding to each average? thanks, Nicole -- Nicole Hackman Master of Science Student University of Washington College of Forest Resources Box 352100 n...@u.washington.edu [[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. -- Mike Lawrence Graduate Student Department of Psychology Dalhousie University www.thatmike.com Looking to arrange a meeting? Check my public calendar: http://www.thatmike.com/mikes-public-calendar ~ Certainty is folly... I think. ~ __ 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] error bars
Nicole Hackman wrote: Hello, I have a very simple data set i imported from excel including 96 averages in a column along with 96 standard errors associated with those averages (calculated in excel). I plotted the 95 averages using r and I am wondering if it is possible to plot the second column of standard errors while applying error bars to each value so they represent the error corresponding to each average? You might also find http://users.fmg.uva.nl/rgrasman/rpages/2005/09/error-bars-in-plots.html this page to be useful; it doesn't require you to load any new packages. -- View this message in context: http://www.nabble.com/error-bars-tp22092367p22095134.html Sent from the R help mailing list archive at Nabble.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] error bars
On Fri, 2008-12-19 at 13:06 +, Kelly-Gerreyn B.A. wrote: Dear Help I'm new to R (from matlab)...using windows XP. I've tried to work out, to no avail, 4 things: 1) rotating the numbers on axes...something to do with par(str) ?? ?par and argument 'las' for basic control. There is a FAQ that explains how to get more control of the rotating: http://cran.r-project.org/doc/FAQ/R-FAQ.html#How-can-I-create-rotated-axis-labels_003f 2) how to close a window having opened one e.g. windows(7,7) [ click on the close button in the window title bar? ;-) ] More seriously, if you are looking for a R function to do it, dev.off() closes the currently active device. dev.list() shows the devices open on your system, dev.cur() tells you which device is currently active and dev.set() switches between opened devices; since from your question I'm guessing you have more than one opened at a time. 3) how to manipulate the key (e.g. dots, lines etc) on the legend. Using pch just gives me the same key for all functions on a plot. Provide a vector of plotting characters, e.g. 'pch = 1:6'. 'pch' only controls the plotting character; 'lwd' controls widths of lines, 'lty' line types. All accept vectors of 'types' so you can specify exactly what you need. i.e. legend (right, legend=c(Model,Obs), pch= 16 )...in this case both Model and Obs are filled circles! 4) how to add error bars (SE or STD) to an xy plot ?arrows arrows() is the easiest way to cook this up yourself from standard graphics calls. Just draw an arrow from value+error to value-error on the axis that has the error. For example, using dummy data: dat - data.frame(A = rnorm(10, mean = 3, sd = 2), B = rnorm(10, 10, sd = 4), C = rnorm(10, 35, sd = 6)) ## something to plot mns - colMeans(dat) ## some uncertainty err - 2 * sd(dat) ## compute space for means +/- err ylims - range(c(mns + err, mns - err)) ## plot plot(mns, ylim = ylims) ## add error bars arrows(1:3, mns + err, 1:3, mns - err, code = 3, angle = 90, length = 0.1) There are functions in several packages to simplify this process for you. Do: RSiteSearch(error bars, restrict=functions) in your R session for lots of hits. These are all fairly basic R fundamentals. Perhaps, if you haven't already done so, take a look at the manual 'An Introduction to R' that comes with R or one of the several user contributed documents: http://cran.r-project.org/other-docs.html HTH G The last is the most important for me right now. All help much appreciated. Many thanks Boris Dr. Boris Kelly-Gerreyn Voiced with Dragonhttp://www.nuance.com/naturallyspeaking/preferred/ http://www.nuance.com/naturallyspeaking/preferred/ NaturallySpeaking v9 http://www.nuance.com/naturallyspeaking/preferred/Ocean Biogeochemistry Ecosystems http://www.noc.soton.ac.uk/obe/ National Oceanography Centre, Southamptonhttp://www.noc.soton.ac.uk/ Waterfront Campus, European Way Southampton, SO14 3ZH, UK Tel : +44 (0) 2380 596334 Sec : +44 (0) 2380 596015 Fax : +44 (0) 2380 596247 e-m: bag'@'noc.soton.ac.uk Friday Seminar http://www.noc.soton.ac.uk/nocs/friday_seminars.php Series http://www.noc.soton.ac.uk/nocs/friday_seminars.phpThis e-mail (and any attachments) is confidential and intended solely for the use of the individual or entity to whom it is addressed. Both NERC and the University of Southampton (who operate NOCS as a collaboration) are subject to the Freedom of Information Act 2000. The information contained in this e-mail and any reply you make may be disclosed unless it is legally exempt from disclosure. Any material supplied to NOCS may be stored in the electronic records management system of either the University or NERC as appropriate. [[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. -- %~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~% Dr. Gavin Simpson [t] +44 (0)20 7679 0522 ECRC, UCL Geography, [f] +44 (0)20 7679 0565 Pearson Building, [e] gavin.simpsonATNOSPAMucl.ac.uk Gower Street, London [w] http://www.ucl.ac.uk/~ucfagls/ UK. WC1E 6BT. [w] http://www.freshwaters.org.uk %~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~% signature.asc Description: This is a digitally signed message part __ 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] error bars
Dear Help I'm new to R (from matlab)...using windows XP. I've tried to work out, to no avail, 4 things: 1) rotating the numbers on axes...something to do with par(str) ?? 2) how to close a window having opened one e.g. windows(7,7) 3) how to manipulate the key (e.g. dots, lines etc) on the legend. Using pch just gives me the same key for all functions on a plot. i.e. legend (right, legend=c(Model,Obs), pch= 16 )...in this case both Model and Obs are filled circles! 4) how to add error bars (SE or STD) to an xy plot The last is the most important for me right now. All help much appreciated. Many thanks Boris Dr. Boris Kelly-Gerreyn Voiced with Dragonhttp://www.nuance.com/naturallyspeaking/preferred/ http://www.nuance.com/naturallyspeaking/preferred/ NaturallySpeaking v9 http://www.nuance.com/naturallyspeaking/preferred/Ocean Biogeochemistry Ecosystems http://www.noc.soton.ac.uk/obe/ National Oceanography Centre, Southamptonhttp://www.noc.soton.ac.uk/ Waterfront Campus, European Way Southampton, SO14 3ZH, UK Tel : +44 (0) 2380 596334 Sec : +44 (0) 2380 596015 Fax : +44 (0) 2380 596247 e-m: bag'@'noc.soton.ac.uk Friday Seminar http://www.noc.soton.ac.uk/nocs/friday_seminars.php Series http://www.noc.soton.ac.uk/nocs/friday_seminars.phpThis e-mail (and any attachments) is confidential and intended solely for the use of the individual or entity to whom it is addressed. Both NERC and the University of Southampton (who operate NOCS as a collaboration) are subject to the Freedom of Information Act 2000. The information contained in this e-mail and any reply you make may be disclosed unless it is legally exempt from disclosure. Any material supplied to NOCS may be stored in the electronic records management system of either the University or NERC as appropriate. [[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] error bars
Hi, These are rather basic; I'd strongly suggest that you at least read An Intro to R, and maybe some of the other excellent beginner materials available. The answers are also easily available through Google, or RSiteSearch. 1) rotating the numbers on axes...something to do with par(str) ?? That's a FAQ: http://cran.r-project.org/doc/FAQ/R-FAQ.html#How-can-I-create-rotated-axis-labels_003f 2) how to close a window having opened one e.g. windows(7,7) dev.off() 3) how to manipulate the key (e.g. dots, lines etc) on the legend. Using pch just gives me the same key for all functions on a plot. i.e. legend (right, legend=c(Model,Obs), pch= 16 )...in this case both Model and Obs are filled circles! If you want more than one kind of symbol, you need to specify that - in your example you only gave pch 16, so that's all that is used. legend() doesn't know anything about your plot. You need something like: legend(right, legend=c(Model,Obs), pch=c(1,2), lty=c(3,4)) 4) how to add error bars (SE or STD) to an xy plot You can draw it yourself with segments(), but easier is to use errbar from the Hmisc package The last is the most important for me right now. All help much appreciated. Sarah -- Sarah Goslee http://www.functionaldiversity.org __ 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] Error bars within xyplot, panel = function(x,y, ....)
All, I'm trying to adapt some code provided by Deepayan Sarkar from a previous thread (https://stat.ethz.ch/pipermail/r-help/2005-October/081571.html) on this topic. ## This code produces a graph w/o error bars: xyplot(Y ~ Hr, data, groups=DRUG, panel=function(x,y,...){ panel.xyplot(x,y,..., type=c(g, l) ) panel.points(x,y,..., pch=16, type='p', col='black', cex=1) }, auto.key = list(space = top, text = c( D,P), points = FALSE, lines = TRUE, columns=2), par.settings = list(superpose.line = list(lty = c(1,5), col=c('black', 'black') ) ) ) ## this code uses the functions provided by Deepayan Sarkar to include the ## error bars for the same data: xyplot(Y ~ Hr, groups=DRUG, data=data, ly = data$lower, uy = data$upper, prepanel = prepanel.ci, panel = panel.superpose, panel.groups = panel.ci, type=b, auto.key = list(space = top, text = c( D,P), points = FALSE, lines = TRUE, columns=2), par.settings = list(superpose.line = list(lty = c(1,5), col=c('black', 'black') ) ) ) Is it possible to write the second version in the format of the first, i.e., using panel = function(x,y, ...){} ? Thanks, David ### load the following: Hr = c(0,1,2,3,4,5,0,1,2,3,4,5) DRUG = rep(c(D, P), each=6) Y = c(1,2,2,2,2,1,3, 4, 4,4, 4, 3) data = data.frame(Hr, DRUG, Y) data$lower = data$Y - .5 data$upper = data$Y + .5 prepanel.ci - function(x, y, ly, uy, subscripts, ...) { x - as.numeric(x) ly - as.numeric(ly[subscripts]) uy - as.numeric(uy[subscripts]) list(ylim = range(y, uy, ly, finite = TRUE)) } panel.ci - function(x, y, ly, uy, subscripts, pch = 16, ...) { x - as.numeric(x) y - as.numeric(y) ly - as.numeric(ly[subscripts]) uy - as.numeric(uy[subscripts]) panel.arrows(x, ly, x, uy, col = black, length = 0.25, unit = native, angle = 90, code = 3) panel.xyplot(x, y, pch = 16, ...)} __ 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] Error bars using data from bugs()
only one out of many many dt = cbind(sim$mean$u2+sim$mean$beta1,sim$sd$u2) dt = dt[order(dt[,1]),] bounds = cbind(c(dt[,1]-1.96*dt[,2],dt[,1]+1.96*dt[,2],dt[,1]),rep(1:length(sim$mean$u2),3)) bounds = bounds[order(bounds[,2]),] plot(bounds) T Matthew Krachey wrote: I'm trying to compare the results of several models using output from bugs(). I want to summarize the models via boxplots or lineplots of the parameters. I know how to use errorbars from a regression, but how do I implement the credible intervals as error bars into these plots Any help is much appreciated Matthew Krachey [[alternative HTML version deleted]] __ [EMAIL PROTECTED] 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.