[R] barplot help needed
hello, I would like to create the following barplot: I have 4 different data sets (same length + stddev for each data point) data1 sd1 data2 sd2 data3 sd3 data4 sd4 now, I'd like to plot in the following way: data1[1],data2[1],data3[1],data4[1] with it's sd-values side-by-side at one x-axis label (named position 1) and each bar in different colors. data1[2],data2[2],data3[2],data4[2] at the next x-axis label (named position 2) with the same color scheme and so on over the whole length. I managed to plot one set in the following way: par(mai=c(1.5,1,1,0.6)) plotInfo - barplot(data1, las=2, ylim = c(0,plotMax+1), ylab = Percentage) arrows(plotInfo,data1,plotInfo, data1 + sd1, length=0.1, angle=90) arrows(plotInfo,data1,plotInfo, data1 - sd1, length=0.1, angle=90) could anybody give me a help on this? Antje __ R-help@stat.math.ethz.ch 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] barplot help needed
tab - do.call(rbind, list(data1, data2, data3, data4)) etype - rep(c(sd1, sd2, sd3, sd4), length(data1)) b - barplot(tab, beside=T) arrows(unlist(b), unlist(tab) - etype, unlist(b), unlist(tab) + etype, code=3) --- Jacques VESLOT CNRS UMR 8090 I.B.L (2ème étage) 1 rue du Professeur Calmette B.P. 245 59019 Lille Cedex Tel : 33 (0)3.20.87.10.44 Fax : 33 (0)3.20.87.10.31 http://www-good.ibl.fr --- Antje a écrit : hello, I would like to create the following barplot: I have 4 different data sets (same length + stddev for each data point) data1 sd1 data2 sd2 data3 sd3 data4 sd4 now, I'd like to plot in the following way: data1[1],data2[1],data3[1],data4[1] with it's sd-values side-by-side at one x-axis label (named position 1) and each bar in different colors. data1[2],data2[2],data3[2],data4[2] at the next x-axis label (named position 2) with the same color scheme and so on over the whole length. I managed to plot one set in the following way: par(mai=c(1.5,1,1,0.6)) plotInfo - barplot(data1, las=2, ylim = c(0,plotMax+1), ylab = Percentage) arrows(plotInfo,data1,plotInfo, data1 + sd1, length=0.1, angle=90) arrows(plotInfo,data1,plotInfo, data1 - sd1, length=0.1, angle=90) could anybody give me a help on this? Antje __ R-help@stat.math.ethz.ch 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@stat.math.ethz.ch 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] barplot help needed
Thank you very much for your help. I just don't understand the following line (which also gives me a dimension error later in the arrows command) etype - rep(c(sd1, sd2, sd3, sd4), length(data1)) Antje (I don't see my emails to the mailinglist anymore... just the answers from other people... I don't understand???) Jacques VESLOT schrieb: tab - do.call(rbind, list(data1, data2, data3, data4)) etype - rep(c(sd1, sd2, sd3, sd4), length(data1)) b - barplot(tab, beside=T) arrows(unlist(b), unlist(tab) - etype, unlist(b), unlist(tab) + etype, code=3) --- Jacques VESLOT CNRS UMR 8090 I.B.L (2ème étage) 1 rue du Professeur Calmette B.P. 245 59019 Lille Cedex Tel : 33 (0)3.20.87.10.44 Fax : 33 (0)3.20.87.10.31 http://www-good.ibl.fr --- Antje a écrit : hello, I would like to create the following barplot: I have 4 different data sets (same length + stddev for each data point) data1 sd1 data2 sd2 data3 sd3 data4 sd4 now, I'd like to plot in the following way: data1[1],data2[1],data3[1],data4[1] with it's sd-values side-by-side at one x-axis label (named position 1) and each bar in different colors. data1[2],data2[2],data3[2],data4[2] at the next x-axis label (named position 2) with the same color scheme and so on over the whole length. I managed to plot one set in the following way: par(mai=c(1.5,1,1,0.6)) plotInfo - barplot(data1, las=2, ylim = c(0,plotMax+1), ylab = Percentage) arrows(plotInfo,data1,plotInfo, data1 + sd1, length=0.1, angle=90) arrows(plotInfo,data1,plotInfo, data1 - sd1, length=0.1, angle=90) could anybody give me a help on this? Antje __ R-help@stat.math.ethz.ch 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@stat.math.ethz.ch 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] barplot help needed
thought sd1, sd2... were scalars but if not just do: etype - c(sd1, sd2, sd3, sd4) --- Jacques VESLOT CNRS UMR 8090 I.B.L (2ème étage) 1 rue du Professeur Calmette B.P. 245 59019 Lille Cedex Tel : 33 (0)3.20.87.10.44 Fax : 33 (0)3.20.87.10.31 http://www-good.ibl.fr --- Antje a écrit : Thank you very much for your help. I just don't understand the following line (which also gives me a dimension error later in the arrows command) etype - rep(c(sd1, sd2, sd3, sd4), length(data1)) Antje (I don't see my emails to the mailinglist anymore... just the answers from other people... I don't understand???) Jacques VESLOT schrieb: tab - do.call(rbind, list(data1, data2, data3, data4)) etype - rep(c(sd1, sd2, sd3, sd4), length(data1)) b - barplot(tab, beside=T) arrows(unlist(b), unlist(tab) - etype, unlist(b), unlist(tab) + etype, code=3) --- Jacques VESLOT CNRS UMR 8090 I.B.L (2ème étage) 1 rue du Professeur Calmette B.P. 245 59019 Lille Cedex Tel : 33 (0)3.20.87.10.44 Fax : 33 (0)3.20.87.10.31 http://www-good.ibl.fr --- Antje a écrit : hello, I would like to create the following barplot: I have 4 different data sets (same length + stddev for each data point) data1 sd1 data2 sd2 data3 sd3 data4 sd4 now, I'd like to plot in the following way: data1[1],data2[1],data3[1],data4[1] with it's sd-values side-by-side at one x-axis label (named position 1) and each bar in different colors. data1[2],data2[2],data3[2],data4[2] at the next x-axis label (named position 2) with the same color scheme and so on over the whole length. I managed to plot one set in the following way: par(mai=c(1.5,1,1,0.6)) plotInfo - barplot(data1, las=2, ylim = c(0,plotMax+1), ylab = Percentage) arrows(plotInfo,data1,plotInfo, data1 + sd1, length=0.1, angle=90) arrows(plotInfo,data1,plotInfo, data1 - sd1, length=0.1, angle=90) could anybody give me a help on this? Antje __ R-help@stat.math.ethz.ch 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@stat.math.ethz.ch 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@stat.math.ethz.ch 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] barplot help needed
Is the length of all your datasets equal? If not try etype - rep(c(sd1, sd2, sd3, sd4), c(length(data1), length(data2), length(data3), length(data4)) Cheers, Thierry ir. Thierry Onkelinx Instituut voor natuur- en bosonderzoek / Reseach Institute for Nature and Forest Cel biometrie, methodologie en kwaliteitszorg / Section biometrics, methodology and quality assurance Gaverstraat 4 9500 Geraardsbergen Belgium tel. + 32 54/436 185 [EMAIL PROTECTED] www.inbo.be Do not put your faith in what statistics say until you have carefully considered what they do not say. ~William W. Watt A statistical analysis, properly conducted, is a delicate dissection of uncertainties, a surgery of suppositions. ~M.J.Moroney -Oorspronkelijk bericht- Van: [EMAIL PROTECTED] [mailto:[EMAIL PROTECTED] Namens Antje Verzonden: vrijdag 24 november 2006 13:42 Aan: r-help@stat.math.ethz.ch Onderwerp: Re: [R] barplot help needed Thank you very much for your help. I just don't understand the following line (which also gives me a dimension error later in the arrows command) etype - rep(c(sd1, sd2, sd3, sd4), length(data1)) Antje (I don't see my emails to the mailinglist anymore... just the answers from other people... I don't understand???) Jacques VESLOT schrieb: tab - do.call(rbind, list(data1, data2, data3, data4)) etype - rep(c(sd1, sd2, sd3, sd4), length(data1)) b - barplot(tab, beside=T) arrows(unlist(b), unlist(tab) - etype, unlist(b), unlist(tab) + etype, code=3) --- Jacques VESLOT CNRS UMR 8090 I.B.L (2ème étage) 1 rue du Professeur Calmette B.P. 245 59019 Lille Cedex Tel : 33 (0)3.20.87.10.44 Fax : 33 (0)3.20.87.10.31 http://www-good.ibl.fr --- Antje a écrit : hello, I would like to create the following barplot: I have 4 different data sets (same length + stddev for each data point) data1 sd1 data2 sd2 data3 sd3 data4 sd4 now, I'd like to plot in the following way: data1[1],data2[1],data3[1],data4[1] with it's sd-values side-by-side at one x-axis label (named position 1) and each bar in different colors. data1[2],data2[2],data3[2],data4[2] at the next x-axis label (named position 2) with the same color scheme and so on over the whole length. I managed to plot one set in the following way: par(mai=c(1.5,1,1,0.6)) plotInfo - barplot(data1, las=2, ylim = c(0,plotMax+1), ylab = Percentage) arrows(plotInfo,data1,plotInfo, data1 + sd1, length=0.1, angle=90) arrows(plotInfo,data1,plotInfo, data1 - sd1, length=0.1, angle=90) could anybody give me a help on this? Antje __ R-help@stat.math.ethz.ch 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@stat.math.ethz.ch 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@stat.math.ethz.ch 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] barplot help needed
Still, there is one problem. The SD-Values don't fit to the bar they belong to. I made the following experiment: data1 - c(2,4,6,2,5) data2 - data1 sd1 - c(0.5,1,1.5,1,2) sd2 - sd1 tab - do.call(rbind, list(data1, data2)) etype - c(sd1,sd2) b - barplot(tab, beside=T) arrows(unlist(b), unlist(tab) - etype, unlist(b), unlist(tab) + etype, code=3) I expect the bars with the same height and the same stddev. The height is okay, but the stddev is messed up... if I do it like this: etype - matrix(c(sd1,sd2), nrow=2, byrow=TRUE) it works (but maybe there is an easier way...) Antje Jacques VESLOT schrieb: thought sd1, sd2... were scalars but if not just do: etype - c(sd1, sd2, sd3, sd4) --- Jacques VESLOT CNRS UMR 8090 I.B.L (2ème étage) 1 rue du Professeur Calmette B.P. 245 59019 Lille Cedex Tel : 33 (0)3.20.87.10.44 Fax : 33 (0)3.20.87.10.31 http://www-good.ibl.fr --- Antje a écrit : Thank you very much for your help. I just don't understand the following line (which also gives me a dimension error later in the arrows command) etype - rep(c(sd1, sd2, sd3, sd4), length(data1)) Antje (I don't see my emails to the mailinglist anymore... just the answers from other people... I don't understand???) Jacques VESLOT schrieb: tab - do.call(rbind, list(data1, data2, data3, data4)) etype - rep(c(sd1, sd2, sd3, sd4), length(data1)) b - barplot(tab, beside=T) arrows(unlist(b), unlist(tab) - etype, unlist(b), unlist(tab) + etype, code=3) --- Jacques VESLOT CNRS UMR 8090 I.B.L (2ème étage) 1 rue du Professeur Calmette B.P. 245 59019 Lille Cedex Tel : 33 (0)3.20.87.10.44 Fax : 33 (0)3.20.87.10.31 http://www-good.ibl.fr --- Antje a écrit : hello, I would like to create the following barplot: I have 4 different data sets (same length + stddev for each data point) data1 sd1 data2 sd2 data3 sd3 data4 sd4 now, I'd like to plot in the following way: data1[1],data2[1],data3[1],data4[1] with it's sd-values side-by-side at one x-axis label (named position 1) and each bar in different colors. data1[2],data2[2],data3[2],data4[2] at the next x-axis label (named position 2) with the same color scheme and so on over the whole length. I managed to plot one set in the following way: par(mai=c(1.5,1,1,0.6)) plotInfo - barplot(data1, las=2, ylim = c(0,plotMax+1), ylab = Percentage) arrows(plotInfo,data1,plotInfo, data1 + sd1, length=0.1, angle=90) arrows(plotInfo,data1,plotInfo, data1 - sd1, length=0.1, angle=90) could anybody give me a help on this? Antje __ R-help@stat.math.ethz.ch 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@stat.math.ethz.ch 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@stat.math.ethz.ch 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] barplot help needed
The arrows are messed up because they are partially outside the borders of the barplot. Try adding a good ylim to the barplot. Something like: b - barplot(tab, beside=T, ylim = c(0, 8)) Cheers, Thierry ir. Thierry Onkelinx Instituut voor natuur- en bosonderzoek / Reseach Institute for Nature and Forest Cel biometrie, methodologie en kwaliteitszorg / Section biometrics, methodology and quality assurance Gaverstraat 4 9500 Geraardsbergen Belgium tel. + 32 54/436 185 [EMAIL PROTECTED] www.inbo.be Do not put your faith in what statistics say until you have carefully considered what they do not say. ~William W. Watt A statistical analysis, properly conducted, is a delicate dissection of uncertainties, a surgery of suppositions. ~M.J.Moroney -Oorspronkelijk bericht- Van: [EMAIL PROTECTED] [mailto:[EMAIL PROTECTED] Namens Antje Verzonden: vrijdag 24 november 2006 16:17 Aan: r-help@stat.math.ethz.ch Onderwerp: Re: [R] barplot help needed Still, there is one problem. The SD-Values don't fit to the bar they belong to. I made the following experiment: data1 - c(2,4,6,2,5) data2 - data1 sd1 - c(0.5,1,1.5,1,2) sd2 - sd1 tab - do.call(rbind, list(data1, data2)) etype - c(sd1,sd2) b - barplot(tab, beside=T) arrows(unlist(b), unlist(tab) - etype, unlist(b), unlist(tab) + etype, code=3) I expect the bars with the same height and the same stddev. The height is okay, but the stddev is messed up... if I do it like this: etype - matrix(c(sd1,sd2), nrow=2, byrow=TRUE) it works (but maybe there is an easier way...) Antje Jacques VESLOT schrieb: thought sd1, sd2... were scalars but if not just do: etype - c(sd1, sd2, sd3, sd4) --- Jacques VESLOT CNRS UMR 8090 I.B.L (2ème étage) 1 rue du Professeur Calmette B.P. 245 59019 Lille Cedex Tel : 33 (0)3.20.87.10.44 Fax : 33 (0)3.20.87.10.31 http://www-good.ibl.fr --- Antje a écrit : Thank you very much for your help. I just don't understand the following line (which also gives me a dimension error later in the arrows command) etype - rep(c(sd1, sd2, sd3, sd4), length(data1)) Antje (I don't see my emails to the mailinglist anymore... just the answers from other people... I don't understand???) Jacques VESLOT schrieb: tab - do.call(rbind, list(data1, data2, data3, data4)) etype - rep(c(sd1, sd2, sd3, sd4), length(data1)) b - barplot(tab, beside=T) arrows(unlist(b), unlist(tab) - etype, unlist(b), unlist(tab) + etype, code=3) --- Jacques VESLOT CNRS UMR 8090 I.B.L (2ème étage) 1 rue du Professeur Calmette B.P. 245 59019 Lille Cedex Tel : 33 (0)3.20.87.10.44 Fax : 33 (0)3.20.87.10.31 http://www-good.ibl.fr --- Antje a écrit : hello, I would like to create the following barplot: I have 4 different data sets (same length + stddev for each data point) data1 sd1 data2 sd2 data3 sd3 data4 sd4 now, I'd like to plot in the following way: data1[1],data2[1],data3[1],data4[1] with it's sd-values side-by-side at one x-axis label (named position 1) and each bar in different colors. data1[2],data2[2],data3[2],data4[2] at the next x-axis label (named position 2) with the same color scheme and so on over the whole length. I managed to plot one set in the following way: par(mai=c(1.5,1,1,0.6)) plotInfo - barplot(data1, las=2, ylim = c(0,plotMax+1), ylab = Percentage) arrows(plotInfo,data1,plotInfo, data1 + sd1, length=0.1, angle=90) arrows(plotInfo,data1,plotInfo, data1 - sd1, length=0.1, angle=90) could anybody give me a help on this? Antje __ R-help@stat.math.ethz.ch 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@stat.math.ethz.ch 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@stat.math.ethz.ch 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@stat.math.ethz.ch 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
Re: [R] barplot help needed
tab - do.call(rbind, list(data1, data2, data3, data4)) etype - do.call(rbind, list(sd1, sd2, sd3, sd4)) b - barplot(tab, beside=T, ylim=c(0,max(tab+etype))) arrows(as.vector(b), as.vector(tab) - as.vector(etype), as.vector(b), as.vector(tab) + as.vector(etype), code=3) unlist() is not correct - sorry - since all are matrices - not data frames ! so use as.vector() --- Jacques VESLOT CNRS UMR 8090 I.B.L (2ème étage) 1 rue du Professeur Calmette B.P. 245 59019 Lille Cedex Tel : 33 (0)3.20.87.10.44 Fax : 33 (0)3.20.87.10.31 http://www-good.ibl.fr --- Antje a écrit : Still, there is one problem. The SD-Values don't fit to the bar they belong to. I made the following experiment: data1 - c(2,4,6,2,5) data2 - data1 sd1 - c(0.5,1,1.5,1,2) sd2 - sd1 tab - do.call(rbind, list(data1, data2)) etype - c(sd1,sd2) b - barplot(tab, beside=T) arrows(unlist(b), unlist(tab) - etype, unlist(b), unlist(tab) + etype, code=3) I expect the bars with the same height and the same stddev. The height is okay, but the stddev is messed up... if I do it like this: etype - matrix(c(sd1,sd2), nrow=2, byrow=TRUE) it works (but maybe there is an easier way...) Antje Jacques VESLOT schrieb: thought sd1, sd2... were scalars but if not just do: etype - c(sd1, sd2, sd3, sd4) --- Jacques VESLOT CNRS UMR 8090 I.B.L (2ème étage) 1 rue du Professeur Calmette B.P. 245 59019 Lille Cedex Tel : 33 (0)3.20.87.10.44 Fax : 33 (0)3.20.87.10.31 http://www-good.ibl.fr --- Antje a écrit : Thank you very much for your help. I just don't understand the following line (which also gives me a dimension error later in the arrows command) etype - rep(c(sd1, sd2, sd3, sd4), length(data1)) Antje (I don't see my emails to the mailinglist anymore... just the answers from other people... I don't understand???) Jacques VESLOT schrieb: tab - do.call(rbind, list(data1, data2, data3, data4)) etype - rep(c(sd1, sd2, sd3, sd4), length(data1)) b - barplot(tab, beside=T) arrows(unlist(b), unlist(tab) - etype, unlist(b), unlist(tab) + etype, code=3) --- Jacques VESLOT CNRS UMR 8090 I.B.L (2ème étage) 1 rue du Professeur Calmette B.P. 245 59019 Lille Cedex Tel : 33 (0)3.20.87.10.44 Fax : 33 (0)3.20.87.10.31 http://www-good.ibl.fr --- Antje a écrit : hello, I would like to create the following barplot: I have 4 different data sets (same length + stddev for each data point) data1 sd1 data2 sd2 data3 sd3 data4 sd4 now, I'd like to plot in the following way: data1[1],data2[1],data3[1],data4[1] with it's sd-values side-by-side at one x-axis label (named position 1) and each bar in different colors. data1[2],data2[2],data3[2],data4[2] at the next x-axis label (named position 2) with the same color scheme and so on over the whole length. I managed to plot one set in the following way: par(mai=c(1.5,1,1,0.6)) plotInfo - barplot(data1, las=2, ylim = c(0,plotMax+1), ylab = Percentage) arrows(plotInfo,data1,plotInfo, data1 + sd1, length=0.1, angle=90) arrows(plotInfo,data1,plotInfo, data1 - sd1, length=0.1, angle=90) could anybody give me a help on this? Antje __ R-help@stat.math.ethz.ch 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@stat.math.ethz.ch 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@stat.math.ethz.ch 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@stat.math.ethz.ch 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.