Re: [R] package to plot mean and standard deviation directly on data
Dear Duncan and Jim, thank you fo ryour reply. Please do not worry about the code: it was just an example of the lenghty procedure I have to apply to plot the standard deviation lines; the actual code is then shaped according to the data at hand. I will have a look at the packages you have suggested. Best regards Luigi On Tue, May 13, 2014 at 1:13 AM, Duncan Mackay dulca...@bigpond.com wrote: Hi Luigi I have not got time at the moment to look at you question but see library(xyplot) demo(intervals) Duncan Duncan Mackay Department of Agronomy and Soil Science University of New England Armidale NSW 2351 Email: home: mac...@northnet.com.au -Original Message- From: r-help-boun...@r-project.org [mailto:r-help-boun...@r-project.org] On Behalf Of Luigi Marongiu Sent: Tuesday, 13 May 2014 03:50 To: r-help@r-project.org Subject: [R] package to plot mean and standard deviation directly on data Dear all, is there a package, preferably not ggplot, to draw the lines for the standard deviation just by providing the vector with the data? more or less as it happens with the boxplot function. the procedure i implemented herein requires the calculation of the means, standard deviations, limits (mean+/-SD) and the horizontal bars as well, everything plotted individually. the packages i have seen on google they all require to calculate the mean/SD prior to the plot. best wishes, luigi # in case you are interested this is the code, which is faulty for the factor of the variable sample my.data-structure(list( group = c( 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2), sample = c( 0, 0, 0, 0, 0, 0, 1, 1, 1, 1, 1, 1, 0, 0, 0, 0, 0, 0, 1, 1, 1, 1, 1, 1, 0, 0, 0, 0, 0, 0, 1, 1, 1, 1, 1, 1), copy = c( 626.01, 584.37, 568.5, 154.76, 146.47, 155.83, 297.64, 291.56, 272.16, 414.19, 402.94, 402.94, 351.11, 274.04, 291.56, 66.82, 39.06, 83.87, 16.98, 45.76, 15, 1.39, 98.25, 13.62, 181.32, 142.49, 108.94, 4.95, 5.92, 4.72, 25.14, 31.12, 40.15, 34.27, 26.93, 24.8)), row.names = c(NA, -36L), class = data.frame) # define subset A-subset(my.data, group==0) # define average and standard deviation avg.A-aggregate(copy ~ sample, A, mean) names(avg.A)-c(samp., avg) sd.A-aggregate(copy ~ sample, A, sd) names(sd.A)-c(Samp, sd) A.bound-merge(avg.A, sd.A, by.x=samp., by.y=Samp) # define limits min.A-A.bound$avg - A.bound$sd max.A-A.bound$avg + A.bound$sd # plot plot(avg ~ samp., data=avg.A, pch=16, ylim=c(-10, 600), las=3, cex.lab=1.5, cex.main=1.8, col=black, ylab=expression(bold(copy)), xlab=expression(bold(sample)), main=Mean and std dev) # add limit segments segments(seq(length(avg.A$sample)), max.A, seq(length(avg.A$sample)), min.A) segments(seq(length(avg.B$sample)), max.B, seq(length(avg.B$sample)), min.B) # add notch notch-0.02 # define end of bar extension segments(seq(length(avg.A$sample))-notch, max.A, seq(length(avg.A$sample))+notch, max.A) segments(seq(length(avg.A$sample))-notch, min.A, seq(length(avg.A$sample))+notch, min.A) __ 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] package to plot mean and standard deviation directly on data
Dear Jim, I have use the brkdn.plot as you suggested and I quite like it since it is easy to use. Would be possible to overlap the confidence bars (SD) with the mean value points? The implemetation leaves a small space as you can see in this figure. I tired with a pch=list(type=o, pch=c(16, 1, 15)) but it did not work. In addition: what are the code, if applicable, for let's say: mean / standard deviation median / min-max mean / 95% confidence interval Here the implemetation is standard error. Compliments for the development of this nice function, Regards luigi # code:: my.data-structure(list( group = c( 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2), sample = c( 0, 0, 0, 0, 0, 0, 1, 1, 1, 1, 1, 1, 0, 0, 0, 0, 0, 0, 1, 1, 1, 1, 1, 1, 0, 0, 0, 0, 0, 0, 1, 1, 1, 1, 1, 1), copy = c( 626.01, 584.37, 568.5, 154.76, 146.47, 155.83, 297.64, 291.56, 272.16, 414.19, 402.94, 402.94, 351.11, 274.04, 291.56, 66.82, 39.06, 83.87, 16.98, 45.76, 15, 1.39, 98.25, 13.62, 181.32, 142.49, 108.94, 4.95, 5.92, 4.72, 25.14, 31.12, 40.15, 34.27, 26.93, 24.8)), row.names = c(NA, -36L), class = data.frame) my.data$sample-factor(my.data$sample, levels = c(0,1)) levels(my.data$sample)-c(first, second) brkdn.plot(copy~group+sample,data=my.data, mct=mean, md=std.error, stagger=NA, dispbar=TRUE, type=p, pch=c(16, 1, 15), main=Breakdown plot, xlab=sample,ylab=value, xaxlab=c(first, second)) On Mon, May 12, 2014 at 10:36 PM, Jim Lemon j...@bitwrit.com.au wrote: On Mon, 12 May 2014 06:50:29 PM Luigi Marongiu wrote: Dear all, is there a package, preferably not ggplot, to draw the lines for the standard deviation just by providing the vector with the data? more or less as it happens with the boxplot function. the procedure i implemented herein requires the calculation of the means, standard deviations, limits (mean+/-SD) and the horizontal bars as well, everything plotted individually. the packages i have seen on google they all require to calculate the mean/SD prior to the plot. best wishes, luigi # in case you are interested this is the code, which is faulty for the factor of the variable sample my.data-structure(list( group = c( 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2), sample = c( 0, 0, 0, 0, 0, 0, 1, 1, 1, 1, 1, 1, 0, 0, 0, 0, 0, 0, 1, 1, 1, 1, 1, 1, 0, 0, 0, 0, 0, 0, 1, 1, 1, 1, 1, 1), copy = c( 626.01, 584.37, 568.5, 154.76, 146.47, 155.83, 297.64, 291.56, 272.16, 414.19, 402.94, 402.94, 351.11, 274.04, 291.56, 66.82, 39.06, 83.87, 16.98, 45.76, 15, 1.39, 98.25, 13.62, 181.32, 142.49, 108.94, 4.95, 5.92, 4.72, 25.14, 31.12, 40.15, 34.27, 26.93, 24.8)), row.names = c(NA, -36L), class = data.frame) # define subset A-subset(my.data, group==0) # define average and standard deviation avg.A-aggregate(copy ~ sample, A, mean) names(avg.A)-c(samp., avg) sd.A-aggregate(copy ~ sample, A, sd) names(sd.A)-c(Samp, sd) A.bound-merge(avg.A, sd.A, by.x=samp., by.y=Samp) # define limits min.A-A.bound$avg - A.bound$sd max.A-A.bound$avg + A.bound$sd # plot plot(avg ~ samp., data=avg.A, pch=16, ylim=c(-10, 600), las=3, cex.lab=1.5, cex.main=1.8, col=black, ylab=expression(bold(copy)), xlab=expression(bold(sample)), main=Mean and std dev) # add limit segments segments(seq(length(avg.A$sample)), max.A, seq(length(avg.A$sample)), min.A) segments(seq(length(avg.B$sample)), max.B, seq(length(avg.B$sample)), min.B) # add notch notch-0.02 # define end of bar extension segments(seq(length(avg.A$sample))-notch, max.A, seq(length(avg.A$sample))+notch, max.A) segments(seq(length(avg.A$sample))-notch, min.A, seq(length(avg.A$sample))+notch, min.A) Hi Luigi, Have a look at brkdn.plot in the plotrix package. 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] package to plot mean and standard deviation directly on data
On Mon, 12 May 2014 06:50:29 PM Luigi Marongiu wrote: Dear all, is there a package, preferably not ggplot, to draw the lines for the standard deviation just by providing the vector with the data? more or less as it happens with the boxplot function. the procedure i implemented herein requires the calculation of the means, standard deviations, limits (mean+/-SD) and the horizontal bars as well, everything plotted individually. the packages i have seen on google they all require to calculate the mean/SD prior to the plot. best wishes, luigi # in case you are interested this is the code, which is faulty for the factor of the variable sample my.data-structure(list( group = c( 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2), sample = c( 0, 0, 0, 0, 0, 0, 1, 1, 1, 1, 1, 1, 0, 0, 0, 0, 0, 0, 1, 1, 1, 1, 1, 1, 0, 0, 0, 0, 0, 0, 1, 1, 1, 1, 1, 1), copy = c( 626.01, 584.37, 568.5, 154.76, 146.47, 155.83, 297.64, 291.56, 272.16, 414.19, 402.94, 402.94, 351.11, 274.04, 291.56, 66.82, 39.06, 83.87, 16.98, 45.76, 15, 1.39, 98.25, 13.62, 181.32, 142.49, 108.94, 4.95, 5.92, 4.72, 25.14, 31.12, 40.15, 34.27, 26.93, 24.8)), row.names = c(NA, -36L), class = data.frame) # define subset A-subset(my.data, group==0) # define average and standard deviation avg.A-aggregate(copy ~ sample, A, mean) names(avg.A)-c(samp., avg) sd.A-aggregate(copy ~ sample, A, sd) names(sd.A)-c(Samp, sd) A.bound-merge(avg.A, sd.A, by.x=samp., by.y=Samp) # define limits min.A-A.bound$avg - A.bound$sd max.A-A.bound$avg + A.bound$sd # plot plot(avg ~ samp., data=avg.A, pch=16, ylim=c(-10, 600), las=3, cex.lab=1.5, cex.main=1.8, col=black, ylab=expression(bold(copy)), xlab=expression(bold(sample)), main=Mean and std dev) # add limit segments segments(seq(length(avg.A$sample)), max.A, seq(length(avg.A$sample)), min.A) segments(seq(length(avg.B$sample)), max.B, seq(length(avg.B$sample)), min.B) # add notch notch-0.02 # define end of bar extension segments(seq(length(avg.A$sample))-notch, max.A, seq(length(avg.A$sample))+notch, max.A) segments(seq(length(avg.A$sample))-notch, min.A, seq(length(avg.A$sample))+notch, min.A) Hi Luigi, Have a look at brkdn.plot in the plotrix package. 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] package to plot mean and standard deviation directly on data
Hi Luigi I have not got time at the moment to look at you question but see library(xyplot) demo(intervals) Duncan Duncan Mackay Department of Agronomy and Soil Science University of New England Armidale NSW 2351 Email: home: mac...@northnet.com.au -Original Message- From: r-help-boun...@r-project.org [mailto:r-help-boun...@r-project.org] On Behalf Of Luigi Marongiu Sent: Tuesday, 13 May 2014 03:50 To: r-help@r-project.org Subject: [R] package to plot mean and standard deviation directly on data Dear all, is there a package, preferably not ggplot, to draw the lines for the standard deviation just by providing the vector with the data? more or less as it happens with the boxplot function. the procedure i implemented herein requires the calculation of the means, standard deviations, limits (mean+/-SD) and the horizontal bars as well, everything plotted individually. the packages i have seen on google they all require to calculate the mean/SD prior to the plot. best wishes, luigi # in case you are interested this is the code, which is faulty for the factor of the variable sample my.data-structure(list( group = c( 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2), sample = c( 0, 0, 0, 0, 0, 0, 1, 1, 1, 1, 1, 1, 0, 0, 0, 0, 0, 0, 1, 1, 1, 1, 1, 1, 0, 0, 0, 0, 0, 0, 1, 1, 1, 1, 1, 1), copy = c( 626.01, 584.37, 568.5, 154.76, 146.47, 155.83, 297.64, 291.56, 272.16, 414.19, 402.94, 402.94, 351.11, 274.04, 291.56, 66.82, 39.06, 83.87, 16.98, 45.76, 15, 1.39, 98.25, 13.62, 181.32, 142.49, 108.94, 4.95, 5.92, 4.72, 25.14, 31.12, 40.15, 34.27, 26.93, 24.8)), row.names = c(NA, -36L), class = data.frame) # define subset A-subset(my.data, group==0) # define average and standard deviation avg.A-aggregate(copy ~ sample, A, mean) names(avg.A)-c(samp., avg) sd.A-aggregate(copy ~ sample, A, sd) names(sd.A)-c(Samp, sd) A.bound-merge(avg.A, sd.A, by.x=samp., by.y=Samp) # define limits min.A-A.bound$avg - A.bound$sd max.A-A.bound$avg + A.bound$sd # plot plot(avg ~ samp., data=avg.A, pch=16, ylim=c(-10, 600), las=3, cex.lab=1.5, cex.main=1.8, col=black, ylab=expression(bold(copy)), xlab=expression(bold(sample)), main=Mean and std dev) # add limit segments segments(seq(length(avg.A$sample)), max.A, seq(length(avg.A$sample)), min.A) segments(seq(length(avg.B$sample)), max.B, seq(length(avg.B$sample)), min.B) # add notch notch-0.02 # define end of bar extension segments(seq(length(avg.A$sample))-notch, max.A, seq(length(avg.A$sample))+notch, max.A) segments(seq(length(avg.A$sample))-notch, min.A, seq(length(avg.A$sample))+notch, min.A) __ 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.