Re: [R] barplot and map overlay
Look at the subplot function in the TeachingDemos package. -Original Message- From: Héctor Villalobos [EMAIL PROTECTED] To: r-help@stat.math.ethz.ch r-help@stat.math.ethz.ch Sent: 6/11/07 5:48 PM Subject: [R] barplot and map overlay Hi, I wonder if it is possible with the graphics package to overlay one or several plots (barplots, for example) over a map. Data for the map is in a data frame with the latitude and longitude coordinates, and then: plot(map$long, map$lat, type =l) produces the map. I want to put each barplot in specific locations on the map, namely at the center of statistical squares. I´ve seen an example in Paul Murrell´s R Graphics book that seems appropriate (grid package), but a bit complicated. Thanks a lot for any advice. Héctor -- Héctor Villalobos [EMAIL PROTECTED] CICIMAR - IPN A.P. 592. Col. Centro La Paz, Baja California Sur, MÉXICO. 23000 Tels. (+52 612) 122 53 44; 123 46 58; 123 47 34 ext. 2425 Fax. (+52 612) 122 53 22 [[alternative HTML version deleted]] __ 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 and map overlay
Thank you Greg, It works! On 13 Jun 2007 at 8:27, Greg Snow wrote: Look at the subplot function in the TeachingDemos package. -Original Message- From: Héctor Villalobos [EMAIL PROTECTED] To: r-help@stat.math.ethz.ch r-help@stat.math.ethz.ch Sent: 6/11/07 5:48 PM Subject: [R] barplot and map overlay Hi, I wonder if it is possible with the graphics package to overlay one or several plots (barplots, for example) over a map. Data for the map is in a data frame with the latitude and longitude coordinates, and then: plot(map$long, map$lat, type =l) produces the map. I want to put each barplot in specific locations on the map, namely at the center of statistical squares. I´ve seen an example in Paul Murrell´s R Graphics book that seems appropriate (grid package), but a bit complicated. Thanks a lot for any advice. Héctor -- Héctor Villalobos [EMAIL PROTECTED] CICIMAR - IPN A.P. 592. Col. Centro La Paz, Baja California Sur, MÉXICO. 23000 Tels. (+52 612) 122 53 44; 123 46 58; 123 47 34 ext. 2425 Fax. (+52 612) 122 53 22 __ 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 by two variables
Thanks for your solution, it worked perfectly, it was exactly what I wanted. I do have two more questions and hope you can help. I have another analysis exactly like the last one except it is done by month instead of year. When I graph it using barchart it makes the months go in alphabetical order. Is there anyway to change it so that the months go in the correct order (jan, feb, march, etc,). And how do I change the colors of the bars in the graph, they are weird colors and I want to change them. Thanks so much for your help. -Original Message- From: Deepayan Sarkar [mailto:[EMAIL PROTECTED] Sent: May 10, 2007 4:58 PM To: Spilak,Jacqueline [Edm] Cc: r-help@stat.math.ethz.ch Subject: Re: [R] Barplot by two variables On 5/10/07, Spilak,Jacqueline [Edm] [EMAIL PROTECTED] wrote: Hi all I have a bit of a problem. I want to make a barplot of some data. My data is of a score that is separated by year and by a limit (above 3 and below 3 to calculate the score). YearLimit HSS 1999ALT 0.675 1999VFR 0.521 2000ALT 0.264 2000VFR 0.295 I would like to have a barplot with year on the x axis and HSS on the y axis and the two limits as two different colors to show the difference. Using (dataset$HSS, col=c(green,purple)) I get some of the plot but I don't know how to get labels on the bottom for each year and I can't get a legend for my barplot. Not really sure what I am doing wrong but any help would be much appreciated. Here's one solution using the lattice package: library(lattice) barchart(HSS ~ factor(Year), data = dataset, origin = 0, groups = Limit, auto.key = TRUE) -Deepayan __ 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 by two variables
On 5/10/07, Spilak,Jacqueline [Edm] [EMAIL PROTECTED] wrote: Hi all I have a bit of a problem. I want to make a barplot of some data. My data is of a score that is separated by year and by a limit (above 3 and below 3 to calculate the score). YearLimit HSS 1999ALT 0.675 1999VFR 0.521 2000ALT 0.264 2000VFR 0.295 I would like to have a barplot with year on the x axis and HSS on the y axis and the two limits as two different colors to show the difference. Using (dataset$HSS, col=c(green,purple)) I get some of the plot but I don't know how to get labels on the bottom for each year and I can't get a legend for my barplot. Not really sure what I am doing wrong but any help would be much appreciated. Here's one solution using the lattice package: library(lattice) barchart(HSS ~ factor(Year), data = dataset, origin = 0, groups = Limit, auto.key = TRUE) -Deepayan __ 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 by two variables
On Thu, 2007-05-10 at 15:58 -0700, Deepayan Sarkar wrote: On 5/10/07, Spilak,Jacqueline [Edm] [EMAIL PROTECTED] wrote: Hi all I have a bit of a problem. I want to make a barplot of some data. My data is of a score that is separated by year and by a limit (above 3 and below 3 to calculate the score). YearLimit HSS 1999ALT 0.675 1999VFR 0.521 2000ALT 0.264 2000VFR 0.295 I would like to have a barplot with year on the x axis and HSS on the y axis and the two limits as two different colors to show the difference. Using (dataset$HSS, col=c(green,purple)) I get some of the plot but I don't know how to get labels on the bottom for each year and I can't get a legend for my barplot. Not really sure what I am doing wrong but any help would be much appreciated. Here's one solution using the lattice package: library(lattice) barchart(HSS ~ factor(Year), data = dataset, origin = 0, groups = Limit, auto.key = TRUE) And here is one using barplot(): DF Year Limit HSS 1 1999 ALT 0.675 2 1999 VFR 0.521 3 2000 ALT 0.264 4 2000 VFR 0.295 barplot(matrix(DF$HSS, ncol = 2), beside = TRUE, names.arg = unique(DF$Year), legend.text = unique(DF$Limit) Note that I convert DF$HSS to a two column matrix to enable using the built-in 'beside' argument in barplot() for the bar pairings, much like Deepayan has used the formula in barchart() above. Then it is a matter of getting the unique values for both the Years and the Limits to use them for the x axis labels and the legend text. HTH, Marc Schwartz __ 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 legend position
However, the legend does not reproduce the color/shading used in the original barplot, are those available somehow? Actually, Ingmar, there's a more elegant way to recre- ate the original colors; to expand on your example: data - 1:10 rows - 2 cols - 5 labels - c('left', 'right') position - 'topleft' colors - gray.colors(rows) inset - c(0.1, 0.1) height = matrix(data, rows, cols) barplot(height, beside=T) legend(position, labels, fill=colors, inset=inset) The key is the `gray.colors()' palette; and `inset' is for beautification. Best, Peter __ 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, for loop?
I put the data again because it looks like it went all mixed up. Data is named pisteet.sum. First row is the header row. kuvaaja kuva yhteispisteet Hannu isokala 8 Hannu kaapin alta löytynyt 2 Hannu kaapin alta löytynyt2 8 Hannu limamikko 1 Hannu maukasta marmeladia 8 Hannu skrinnareita 4 Hate madekoukkujen suojelupyhimys 3 Hate matka aikaan joka ei enää palaa 3 Hate munat puoliks padassa 6 Hate pyynikki 2 Hate vailla armeerausta 2 Lassi ajatelkaa, jos Häntä ei olisikaan 2 Lassi elämän viiva 7 Lassi pedot 1 Lassi portsan kundi 3 Lauri hipö 3 Lauri jääpuut 5 Lauri kökar 3 Lauri lumipuu 9 Petteri harmaaleppä 5 Petteri viileä harakka 2 Teemu harppi 2 Teemu Homo sapiens angelus 3 Teemu kainostelua 1 Teemu pinnalla 5 Teemu portinvartija 6 Teemu puikot 1 Teemu verkkovaja 3 10.3.2007 Lauri Nikkinen [EMAIL PROTECTED] kirjoitti: Hi R-users, -Lauri I have a dataset like this: kuvaaja kuva yhteispisteet Hannu isokala 8 Hannu kaapin alta löytynyt 2 Hannu kaapin alta löytynyt 2 8 Hannu limamikko 1 Hannu maukasta marmeladia 8 Hannu skrinnareita 4 Hate madekoukkujen suojelupyhimys 3 Hate matka aikaan joka ei enää palaa 3 Hate munat puoliks padassa 6 Hate pyynikki 2 Hate vailla armeerausta 2 Lassi ajatelkaa, jos Häntä ei olisikaan 2 Lassi elämän viiva 7 Lassi pedot 1 Lassi portsan kundi 3 Lauri hipö 3 Lauri jääpuut 5 Lauri kökar 3 Lauri lumipuu 9 Petteri harmaaleppä 5 Petteri viileä harakka 2 Teemu harppi 2 Teemu Homo sapiens angelus 3 Teemu kainostelua 1 Teemu pinnalla 5 Teemu portinvartija 6 Teemu puikot 1 Teemu verkkovaja 3 I have done this: pisteet.hannu - subset(pisteet.sum, kuvaaja == Hannu, select=c(kuva, yhteispisteet)) (pisteet.hannu - pisteet.hannu[rev(order(pisteet.hannu$yhteispisteet)),]) pisteet.lauri - subset(pisteet.sum, kuvaaja == Lauri, select=c(kuva, yhteispisteet)) (pisteet.lauri - pisteet.lauri[rev(order(pisteet.lauri$yhteispisteet)),]) pisteet.lassi - subset(pisteet.sum, kuvaaja == Lassi, select=c(kuva, yhteispisteet)) (pisteet.lassi - pisteet.lassi[rev(order(pisteet.lassi$yhteispisteet)),]) pisteet.teemu - subset(pisteet.sum, kuvaaja == Teemu, select=c(kuva, yhteispisteet)) (pisteet.teemu - pisteet.teemu[rev(order(pisteet.teemu$yhteispisteet)),]) pisteet.petteri - subset(pisteet.sum, kuvaaja == Petteri, select=c(kuva, yhteispisteet)) (pisteet.petteri - pisteet.petteri[rev(order( pisteet.petteri$yhteispisteet)),]) pisteet.hate - subset(pisteet.sum, kuvaaja == Hate, select=c(kuva, yhteispisteet)) (pisteet.hate - pisteet.hate[rev(order(pisteet.hate$yhteispisteet)),]) opar - par(mfrow=c(2,3), mar=c(11,3,3,3)) barplot(as.vector(pisteet.hannu$yhteispisteet), names.arg=as.vector(pisteet.hannu$kuva), las=3, cex.names=0.8, main=Hannu, ylim=c(0,10) ) barplot(as.vector(pisteet.lauri$yhteispisteet), names.arg=as.vector(pisteet.lauri$kuva), las=3, cex.names=0.8, main=Lauri, ylim=c(0,10) ) barplot(as.vector(pisteet.lassi$yhteispisteet), names.arg=as.vector(pisteet.lassi$kuva), las=3, cex.names=0.8, main=Lassi, ylim=c(0,10) ) barplot(as.vector(pisteet.teemu$yhteispisteet), names.arg=as.vector(pisteet.teemu$kuva), las=3, cex.names=0.8, main=Teemu, ylim=c(0,10) ) barplot(as.vector(pisteet.petteri$yhteispisteet), names.arg=as.vector(pisteet.petteri$kuva), las=3, cex.names=0.8, main=Petteri, ylim=c(0,10) ) barplot(as.vector(pisteet.hate$yhteispisteet), names.arg=as.vector(pisteet.hate$kuva), las=3, cex.names=0.8, main=Hate, ylim=c(0,10) ) par(opar) Queston is: how do I do this more effectively e.g. using for loop (without subsetting, straight from the original data)? Thanks in advance! -Lauri [[alternative HTML version deleted]] __ 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, for loop?
Here is one way of doing it. x - 'kuvaaja kuva yhteispisteet Hannu isokala 8 Hannu kaapin alta löytynyt 2 Hannu kaapin alta löytynyt2 8 Hannu limamikko 1 Hannu maukasta marmeladia 8 Hannu skrinnareita 4 Hate madekoukkujen suojelupyhimys 3 Hate matka aikaan joka ei enää palaa 3 Hate munat puoliks padassa 6 Hate pyynikki 2 Hate vailla armeerausta 2 Lassi ajatelkaa, jos Häntä ei olisikaan 2 Lassi elämän viiva 7 Lassi pedot 1 Lassi portsan kundi 3 Lauri hipö 3 Lauri jääpuut 5 Lauri kökar 3 Lauri lumipuu 9 Petteri harmaaleppä 5 Petteri viileä harakka 2 Teemu harppi 2 Teemu Homo sapiens angelus 3 Teemu kainostelua 1 Teemu pinnalla 5 Teemu portinvartija 6 Teemu puikot 1 Teemu verkkovaja 3' # read in the data x.in - read.table(textConnection(x), header=TRUE) # split data by groups x.ku - split(x.in, x.in$kuvaaja) # iterate through each group for (i in names(x.ku)){ # sort the data in decending order .order - rev(order(x.ku[[i]]$yhteispisteet)) # plot it barplot(x.ku[[i]]$yhteispisteet[.order], names.arg=as.character(x.ku[[i]]$kuva[.order]), las=3, cex.names=0.8, main=i, ylim=c(0,10) ) } On 3/10/07, Lauri Nikkinen [EMAIL PROTECTED] wrote: Hi R-users, I have a dataset like this: kuvaaja kuva yhteispisteet Hannu isokala 8 Hannu kaapin alta löytynyt 2 Hannu kaapin alta löytynyt 2 8 Hannu limamikko 1 Hannu maukasta marmeladia 8 Hannu skrinnareita 4 Hate madekoukkujen suojelupyhimys 3 Hate matka aikaan joka ei enää palaa 3 Hate munat puoliks padassa 6 Hate pyynikki 2 Hate vailla armeerausta 2 Lassi ajatelkaa, jos Häntä ei olisikaan 2 Lassi elämän viiva 7 Lassi pedot 1 Lassi portsan kundi 3 Lauri hipö 3 Lauri jääpuut 5 Lauri kökar 3 Lauri lumipuu 9 Petteri harmaaleppä 5 Petteri viileä harakka 2 Teemu harppi 2 Teemu Homo sapiens angelus 3 Teemu kainostelua 1 Teemu pinnalla 5 Teemu portinvartija 6 Teemu puikot 1 Teemu verkkovaja 3 I have done this: pisteet.hannu - subset(pisteet.sum, kuvaaja == Hannu, select=c(kuva, yhteispisteet)) (pisteet.hannu - pisteet.hannu[rev(order(pisteet.hannu$yhteispisteet)),]) pisteet.lauri - subset(pisteet.sum, kuvaaja == Lauri, select=c(kuva, yhteispisteet)) (pisteet.lauri - pisteet.lauri[rev(order(pisteet.lauri$yhteispisteet)),]) pisteet.lassi - subset(pisteet.sum, kuvaaja == Lassi, select=c(kuva, yhteispisteet)) (pisteet.lassi - pisteet.lassi[rev(order(pisteet.lassi$yhteispisteet)),]) pisteet.teemu - subset(pisteet.sum, kuvaaja == Teemu, select=c(kuva, yhteispisteet)) (pisteet.teemu - pisteet.teemu[rev(order(pisteet.teemu$yhteispisteet)),]) pisteet.petteri - subset(pisteet.sum, kuvaaja == Petteri, select=c(kuva, yhteispisteet)) (pisteet.petteri - pisteet.petteri[rev(order( pisteet.petteri$yhteispisteet )),]) pisteet.hate - subset(pisteet.sum, kuvaaja == Hate, select=c(kuva, yhteispisteet)) (pisteet.hate - pisteet.hate[rev(order(pisteet.hate$yhteispisteet)),]) opar - par(mfrow=c(2,3), mar=c(11,3,3,3)) barplot(as.vector(pisteet.hannu$yhteispisteet), names.arg=as.vector(pisteet.hannu$kuva), las=3, cex.names=0.8, main=Hannu, ylim=c(0,10) ) barplot(as.vector(pisteet.lauri$yhteispisteet), names.arg=as.vector(pisteet.lauri$kuva), las=3, cex.names=0.8, main=Lauri, ylim=c(0,10) ) barplot(as.vector(pisteet.lassi$yhteispisteet), names.arg=as.vector(pisteet.lassi$kuva), las=3, cex.names=0.8, main=Lassi, ylim=c(0,10) ) barplot(as.vector(pisteet.teemu$yhteispisteet), names.arg=as.vector(pisteet.teemu$kuva), las=3, cex.names=0.8, main=Teemu, ylim=c(0,10) ) barplot(as.vector(pisteet.petteri$yhteispisteet), names.arg=as.vector(pisteet.petteri$kuva), las=3, cex.names=0.8, main=Petteri, ylim=c(0,10) ) barplot(as.vector(pisteet.hate$yhteispisteet), names.arg=as.vector(pisteet.hate$kuva), las=3, cex.names=0.8, main=Hate, ylim=c(0,10) ) par(opar) Queston is: how do I do this more effectively e.g. using for loop (without subsetting, straight from the original data)? Thanks in advance! -Lauri [[alternative HTML version deleted]] __ 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. -- Jim Holtman Cincinnati, OH +1 513 646 9390 What is the problem you are trying to solve? [[alternative HTML version deleted]]
Re: [R] barplot with different color combination for each bar
Hi, I'd suggest you use ?rect for this. Here's an example (I did not check whether it's correct...) I also improved (but not checked :) your definition of cols. Jonne. X - seq(1:6) Q - matrix(sample(X, 60, replace = T), nrow=6, byrow = T) H - matrix(rep(1,60), nrow=6, byrow=T) color - c(blue, orange, gold, indianred, skyblue4, lightblue) cols - matrix(data=color[Q], ncol=10) # Old: barplot(H, col=cols, width = c(0.1), xlim = c(0,3), beside=F) # New: x11() plot(0, 0, type=n, ylim=c(0,nrow(Q)), xlim=c(0,ncol(Q)), xlab=xlabel, ylab=) xleft - rep(1:ncol(Q), each=nrow(Q)) ybottom - rep(1:nrow(Q), times=ncol(Q)) rect(xleft-1, ybottom-1, xleft, ybottom, col=cols) On Fri, 2007-03-02 at 09:48 -0600, Kim Milferstedt wrote: Hi, I'd like to construct a somewhat unusual barplot. In barplot I use beside=F as I'd like to have stacked bars. The height of each bar is always the same. Information in my plot is coded in the color of the bar. I therefore need to be able so assign a different combination (or order) of colors to each individual stacked bar. In the example below, the combination of colors for my plot is generated by X, Q, color and cols. These colors are supposed to fill the stacked bars with the height of H. However, only the first column of cols is used for all columns of H as barplot only allows me to assign one vector for the color scheme of the entire barplot. Does anybody know a way how I can assign each bar a potentially unique color combination? Thanks for your help! Kim X - seq(1:6) Q- matrix(sample(X, 60, replace = T), nrow=6, byrow = T) H - matrix(rep(1,60), nrow=6, byrow=T) color - c(blue, orange, gold, indianred, skyblue4, lightblue) cols - ifelse( (Q ==1) , color[1], ifelse( (Q ==2), color[2], ifelse( (Q ==3) , color[3], ifelse( (Q ==4), color[4], ifelse( (Q ==5) , color[5], color[6] ) ) ) ) ) barplot( H, col=cols, width = c(0.1), xlim = c(0,3), beside=F ) __ Kim Milferstedt University of Illinois at Urbana-Champaign Department of Civil and Environmental Engineering 4125 Newmark Civil Engineering Laboratory 205 North Mathews Avenue MC-250 Urbana, IL 61801 USA phone: (001) 217 333-9663 fax: (001) 217 333-6968 email: [EMAIL PROTECTED] http://cee.uiuc.edu/research/morgenroth __ 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 x-axis problem
Thank you very much, Marc! That was exactly the solution I was looking for! Regards, Lauri 2007/1/26, Marc Schwartz [EMAIL PROTECTED]: On Thu, 2007-01-25 at 22:23 +0200, Lauri Nikkinen wrote: Hi R-users, I'm new to R and I'm trying to make a barplot combined with two lines (refering to secondary y-axis). Bars should represent the number of transfused patients by age class and sex and lines should represent the amount of blood units given in age classes. I have now successfully made a barplot and used par(new=TRUE) to plot another empty graph at the top of the barplot. #tab-table: #ikar_new #sp 0-9 10-19 20-29 30-39 40-49 50-59 60-69 70-79 80 # mies 227937992 195 451 560 577 132 # nainen 18380 102 17599 161 230 357 164 barplot(tab, beside=TRUE, col = c(black, lightgrey), legend = rownames(tab), ylim= c(0,800), font.main = 4, cex.names = 1.1, main = Transfused patients and trombocytes given by age and sex, ylab=Number of transfused patients, xlab=Age groups (years)) axis(1, c(0,3.5+3*0:9), labels=FALSE, tick=TRUE) par(new=TRUE) #temp-table # ikar_new mies nainen #1 0-9 2296 2224 #210-19 1648 3508 #320-29 2276 1464 #430-39 1920 2600 #540-49 3912 2020 #650-59 6856 2872 #760-69 8748 3592 #870-79 7052 4916 #9 80 1436 1780 plot(temp$mies, type=n, yaxt='n', xaxt='n', ann=FALSE) lines(temp$mies, col=blue, lwd=2) lines(temp$nainen, col=red, lwd=2) axis(4, at=NULL) I have used lines() to draw the lines into the picture. How can I get the lines into the same x-axis and get the actual data points of the lines to be exactly in between the two barplot's bars (categories in x-axis)? Now the points which the lines connect are not in the middle of the groups in x-axis as I would want them to be. The bars in the barplot are not stacked. I'm sorry that I'm not able to give you the scripts to make those tables. I suspect that this is what you might require: # Get the maximum value for both sets of data # divide the second set by 10 to normalize to the # range of the first set Max.y - max(tab, as.matrix(temp[, -1]) / 10) # Now do the barplot using c(0, Max.y) for ylim # Also save the bar midpoints in 'mp' # See ?barplot mp - barplot(tab, beside=TRUE, col = c(black, lightgrey), legend = rownames(tab), ylim = c(0, Max.y), font.main = 4, cex.names = 1.1, main = Transfused patients and trombocytes given by age and sex, ylab =Number of transfused patients, xlab =Age groups (years)) axis(1, c(0, 3.5 + 3 * 0:9), labels = FALSE, tick = TRUE) # Now add the lines, dividing the y values by 10 # to fit the y axis range to the first set of data # Use colMeans(mp) for the x axis values, which will # give the midpoints of each bar pair lines(colMeans(mp), temp$mies / 10, col = blue, lwd = 2) lines(colMeans(mp), temp$nainen / 10, col = red, lwd = 2) # Now set the values for the right hand axis at - seq(0, 800, 200) # Set the axis labels to y at * 10 axis(4, at = at, labels = at * 10) There are multiple ways to accomplish drawing two sets of data with differing ranges on the same plot. Typically they involve the normalization of the data to common ranges and then adjustment of the axis labelling accordingly. HTH, Marc Schwartz [[alternative HTML version deleted]] __ 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 x-axis problem
On Thu, 2007-01-25 at 22:23 +0200, Lauri Nikkinen wrote: Hi R-users, I'm new to R and I'm trying to make a barplot combined with two lines (refering to secondary y-axis). Bars should represent the number of transfused patients by age class and sex and lines should represent the amount of blood units given in age classes. I have now successfully made a barplot and used par(new=TRUE) to plot another empty graph at the top of the barplot. #tab-table: #ikar_new #sp 0-9 10-19 20-29 30-39 40-49 50-59 60-69 70-79 80 # mies 227937992 195 451 560 577 132 # nainen 18380 102 17599 161 230 357 164 barplot(tab, beside=TRUE, col = c(black, lightgrey), legend = rownames(tab), ylim= c(0,800), font.main = 4, cex.names = 1.1, main = Transfused patients and trombocytes given by age and sex, ylab=Number of transfused patients, xlab=Age groups (years)) axis(1, c(0,3.5+3*0:9), labels=FALSE, tick=TRUE) par(new=TRUE) #temp-table # ikar_new mies nainen #1 0-9 2296 2224 #210-19 1648 3508 #320-29 2276 1464 #430-39 1920 2600 #540-49 3912 2020 #650-59 6856 2872 #760-69 8748 3592 #870-79 7052 4916 #9 80 1436 1780 plot(temp$mies, type=n, yaxt='n', xaxt='n', ann=FALSE) lines(temp$mies, col=blue, lwd=2) lines(temp$nainen, col=red, lwd=2) axis(4, at=NULL) I have used lines() to draw the lines into the picture. How can I get the lines into the same x-axis and get the actual data points of the lines to be exactly in between the two barplot's bars (categories in x-axis)? Now the points which the lines connect are not in the middle of the groups in x-axis as I would want them to be. The bars in the barplot are not stacked. I'm sorry that I'm not able to give you the scripts to make those tables. I suspect that this is what you might require: # Get the maximum value for both sets of data # divide the second set by 10 to normalize to the # range of the first set Max.y - max(tab, as.matrix(temp[, -1]) / 10) # Now do the barplot using c(0, Max.y) for ylim # Also save the bar midpoints in 'mp' # See ?barplot mp - barplot(tab, beside=TRUE, col = c(black, lightgrey), legend = rownames(tab), ylim = c(0, Max.y), font.main = 4, cex.names = 1.1, main = Transfused patients and trombocytes given by age and sex, ylab =Number of transfused patients, xlab =Age groups (years)) axis(1, c(0, 3.5 + 3 * 0:9), labels = FALSE, tick = TRUE) # Now add the lines, dividing the y values by 10 # to fit the y axis range to the first set of data # Use colMeans(mp) for the x axis values, which will # give the midpoints of each bar pair lines(colMeans(mp), temp$mies / 10, col = blue, lwd = 2) lines(colMeans(mp), temp$nainen / 10, col = red, lwd = 2) # Now set the values for the right hand axis at - seq(0, 800, 200) # Set the axis labels to y at * 10 axis(4, at = at, labels = at * 10) There are multiple ways to accomplish drawing two sets of data with differing ranges on the same plot. Typically they involve the normalization of the data to common ranges and then adjustment of the axis labelling accordingly. HTH, Marc Schwartz __ 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 - how to force vertical axis to cover entire plot area
Hi, Etienne, I've seen this while working with barplot and never been able to understand the general rule, but by setting ylim high enough, I've always been able to draw a y axis covering the biggest values. Could you send a data subset to reproduce the issue? Thanks. Best, Ricardo -- Ricardo Rodríguez Your XEN ICT Team Etienne[EMAIL PROTECTED] 7/12/2006 01:43 I'm using barplot with the following call: barplot(stat_data[[5]][,],axes=TRUE,axisnames=TRUE,axis.lty=1,xlab=xlab,ylab=ylab,beside=TRUE,las=1,font.lab=2,font.axis=1,legend.text=TRUE) On some data, the vertical axis does not cover the whole plot area and the last tick mark is smaller than the maximum value. I tried setting the ylim values but even with that, some plots are still not OK, it just shrinks the length of the bars. Attached is a png example of the problem. I hope it gets through. Thanks, Etienne __ 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 - how to force vertical axis to cover entire plot area
Etienne wrote: I'm using barplot with the following call: barplot(stat_data[[5]][,],axes=TRUE,axisnames=TRUE,axis.lty=1,xlab=xlab,ylab=ylab,beside=TRUE,las=1,font.lab=2,font.axis=1,legend.text=TRUE) The example is not reproducible and poorly formatted. Please read the posting guide. On some data, the vertical axis does not cover the whole plot area and the last tick mark is smaller than the maximum value. I tried setting the ylim values but even with that, some plots are still not OK, it just shrinks the length of the bars. R tries to make the plot pretty, i.e. stop with some tick mark like 200, but not e.g. 242. Perhaps you want to make a box() around the plot? Uwe Ligges Attached is a png example of the problem. I hope it gets through. Thanks, Etienne __ __ 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
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.
Re: [R] barplot - x-axis
Hi barplot(data, las=2, ylim = c(0,plotMax+1), ylab = Percentage, main = filename, sub = subtitle) Error in barplot.default(data, las = 2, ylim = c(0, plotMax + 1), ylab = Percentage, : 'height' must be a vector or a matrix Your code gives me an error, as I do not have data file.Try to use oma and title with outer option set as TRUE. See ?title, ?par But it depends on your intention. and actual lookout of your plot. HTH Petr On 23 Nov 2006 at 15:57, Antje wrote: Date sent: Thu, 23 Nov 2006 15:57:39 +0100 From: Antje [EMAIL PROTECTED] To: R-help@stat.math.ethz.ch Subject:[R] barplot - x-axis Hi there, I have a barplot and the labels at the x-axis are strings, which are rotated by 90°. But now the sub-title of the barplot is in between these labels, which does not look very nice... Could anybody help me finding the parameter-setting to prevent this? par(mai=c(1.5,1,1,0.6)) barplot(data, las=2, ylim = c(0,plotMax+1), ylab = Percentage, main = filename, sub = subtitle) Thank you! 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. Petr Pikal [EMAIL PROTECTED] __ 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
Qian Wan wrote: Hi, I have about 500 data entry ranging from -50 to 10,000. when I barplot(data), it plots all 500 of them individually. How can I set a ranges to group these 500 numbers into 10 or 20 groups, and plot the value of the ranges with how many numbers are in the range. Maybe something along these lines: Y - c(-50, 1, sample(-50:1, size=498, replace=TRUE)) par(mar = c(8, 5, 5, 5)) X - barplot(table(cut(Y, breaks=c(-50, seq(0, 1, 1000)), include.lowest=TRUE)), xaxt = n, xlab = ) text(X, -2, srt = 45, adj = 1, labels = levels(cut(Y, breaks=c(-50, seq(0, 1, 1000)), include.lowest=TRUE)), xpd = TRUE) ?cut for more details on forming the groups. Also, have you considered hist() ? Thanks a lot, Q. __ 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. -- Chuck Cleland, Ph.D. NDRI, Inc. 71 West 23rd Street, 8th floor New York, NY 10010 tel: (212) 845-4495 (Tu, Th) tel: (732) 512-0171 (M, W, F) fax: (917) 438-0894 __ 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 error
On 10/17/06, Farrel Buchinsky [EMAIL PROTECTED] wrote: I created a dataframe called OSA here is what it looks like no.surgery surgery 00.4 6.9 60.2 0.3 I have also attached it as an R data file I cannot understand why I am getting the following error. barplot(OSA) Error in barplot.default(OSA) : 'height' must be a vector or a matrix OSA is a data.frame which means R should see it as a matrix. What am I not understanding? A data.frame is not the same as a matrix. Try one of these using the builtin BOD data frame: barplot(as.matrix(BOD)) barplot(data.matrix(BOD)) barplot.data.frame - function(height, ...) barplot(as.matrix(height), ...) barplot(BOD) __ 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 question
Try RSiteSearch(rotate barplot labels) Then read the first thread for an example of what you want to do. Cheers Francisco Dr. Francisco J. Zagmutt College of Veterinary Medicine and Biomedical Sciences Colorado State University From: Leeds, Mark (IED) [EMAIL PROTECTED] To: R-help@stat.math.ethz.ch Subject: [R] barplot question Date: Tue, 17 Oct 2006 17:15:43 -0400 i'm doing a bar plot and there are 16 column variables. is there a way to make the variable names go down instead of across when you do the barplot ? because the names are so long, the barplot just shows 3 names and leaves the rest out. if i could rotate the names 90 degrees, it would probably fit a lot more. or maybe i can use space to make the horizontal width longer ? I looed up ?barlot but i'm not sure. when 1st and 2nd are on the bottom, things look fine but i'm not as interesed in those 2 barplots. i didn't use any special options. i just did barplot(probsignmatrix) barplot(t(probsignmatrix)) barplot(probsignmatrix,beside=T) barplot(t(probsignmatrix),beside=T) i put probsignmatrix below in case someone wants to see what i mean because it may not be clear. i don't expect anyone to type it in but rounding would still show what i mean. thanks a lot. pcount pmpppcount pmmppcount pmmmpcount pcount mcount pppmmcount ppmmmcount ppmppcount ppmmpcount pppmpcount ppmpmcount pmpmpcount pmpmmcount pmmpmcount pmppmcount 1st 0.03477157 0.02842640 0.03157360 0.03365482 0.04010152 0.03553299 0.03989848 0.04182741 0.02817259 0.03203046 0.02781726 0.02218274 0.01771574 0.02289340 0.02583756 0.02390863 2nd 0.04648895 0.02901495 0.03092490 0.03064044 0.04108420 0.03998700 0.03958062 0.04059655 0.03039662 0.03027471 0.02901495 0.02170026 0.01601105 0.02287874 0.02165962 0.02267555 This is not an offer (or solicitation of an offer) to buy/sell the securities/instruments mentioned or an official confirmation. Morgan Stanley may deal as principal in or own or act as market maker for securities/instruments mentioned or may advise the issuers. This is not research and is not from MS Research but it may refer to a research analyst/research report. Unless indicated, these views are the author's and may differ from those of Morgan Stanley research or others in the Firm. We do not represent this is accurate or complete and we may not update this. Past performance is not indicative of future returns. For additional information, research reports and important disclosures, contact me or see https://secure.ms.com/servlet/cls. You should not use e-mail to request, authorize or effect the purchase or sale of any security or instrument, to send transfer instructions, or to effect any other transactions. We cannot guarantee that any such requests received via ! e-mail will be processed in a timely manner. This communication is solely for the addressee(s) and may contain confidential information. We do not waive confidentiality by mistransmission. Contact me if you do not wish to receive these communications. In the UK, this communication is directed in the UK to those persons who are market counterparties or intermediate customers (as defined in the UK Financial Services Authority's rules). [[alternative HTML version deleted]] __ 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 question
Mark i'm doing a bar plot and there are 16 column variables. is there a way to make the variable names go down instead of across when you do the barplot ? because the names are so long, the barplot just shows 3 names and leaves the rest out. if i could rotate the names 90 degrees, it would probably fit a lot more. Is this the sort of thing you mean: temp - barplot(rnorm(16, 3)) text(temp, rep(-0.2, 16), paste('trt', 1:16), srt=90, adj=1) Peter Alspach or maybe i can use space to make the horizontal width longer ? I looed up ?barlot but i'm not sure. when 1st and 2nd are on the bottom, things look fine but i'm not as interesed in those 2 barplots. i didn't use any special options. i just did barplot(probsignmatrix) barplot(t(probsignmatrix)) barplot(probsignmatrix,beside=T) barplot(t(probsignmatrix),beside=T) i put probsignmatrix below in case someone wants to see what i mean because it may not be clear. i don't expect anyone to type it in but rounding would still show what i mean. thanks a lot. pcount pmpppcount pmmppcount pmmmpcount pcount mcount pppmmcount ppmmmcount ppmppcount ppmmpcount pppmpcount ppmpmcount pmpmpcount pmpmmcount pmmpmcount pmppmcount 1st 0.03477157 0.02842640 0.03157360 0.03365482 0.04010152 0.03553299 0.03989848 0.04182741 0.02817259 0.03203046 0.02781726 0.02218274 0.01771574 0.02289340 0.02583756 0.02390863 2nd 0.04648895 0.02901495 0.03092490 0.03064044 0.04108420 0.03998700 0.03958062 0.04059655 0.03039662 0.03027471 0.02901495 0.02170026 0.01601105 0.02287874 0.02165962 0.02267555 __ The contents of this e-mail are privileged and/or confidenti...{{dropped}} __ 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 question
On 10/17/06, Leeds, Mark (IED) [EMAIL PROTECTED] wrote: i'm doing a bar plot and there are 16 column variables. is there a way to make the variable names go down instead of across when you do the barplot ? because the names are so long, the barplot just shows 3 names and leaves the rest out. if i could rotate the names 90 degrees, it would probably fit a lot more. or maybe i can use space to make the horizontal width longer ? I looed up ?barlot but i'm not sure. when 1st and 2nd are on the bottom, things look fine but i'm not as interesed in those 2 barplots. i didn't use any special options. i just did barplot(probsignmatrix) barplot(t(probsignmatrix)) barplot(probsignmatrix,beside=T) barplot(t(probsignmatrix),beside=T) i put probsignmatrix below in case someone wants to see what i mean because it may not be clear. i don't expect anyone to type it in but rounding would still show what i mean. thanks a lot. pcount pmpppcount pmmppcount pmmmpcount pcount mcount pppmmcount ppmmmcount ppmppcount ppmmpcount pppmpcount ppmpmcount pmpmpcount pmpmmcount pmmpmcount pmppmcount 1st 0.03477157 0.02842640 0.03157360 0.03365482 0.04010152 0.03553299 0.03989848 0.04182741 0.02817259 0.03203046 0.02781726 0.02218274 0.01771574 0.02289340 0.02583756 0.02390863 2nd 0.04648895 0.02901495 0.03092490 0.03064044 0.04108420 0.03998700 0.03958062 0.04059655 0.03039662 0.03027471 0.02901495 0.02170026 0.01601105 0.02287874 0.02165962 0.02267555 Don't know if you want to go this way, but try library(lattice) barchart(t(probsignmatrix)) -Deepayan __ 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
Specify margins using par(mar=c(5,1,4,2)) before the call to barplot. You won't be able to see the vertical axis labels with those settings, though. On 16/10/06, Mohsen Jafarikia [EMAIL PROTECTED] wrote: Hello everyone: I am using the following code to draw my barplot but it has two problems. BL-c(1.97,8.04,2.54,10.53,4.85,1.73) LR-c(0.85,0.86,8.33,04.18,6.26,2.40) Q-c(0.00,0.00,1.92,01.92,4.48,0.00) cols - ifelse(Q!=0, orange, green) Graph- barplot(LR, main='LR Value',col=cols, border='black', space=0.05, width=(BL), xlab='Length', ylab='LR block',mar=c(5,1,4,2)) axis(1, at=Graph, sprintf('%0.2f',BL)) mtext(1, at=Graph, text=ifelse(Q!=0, sprintf('%0.2f',Q), ), line=2) mtext(1, at=par('usr')[1], text='BL', line=1) mtext(1, at=par('usr')[1], text='Var', line=2) abline(h=3.84,col='blue') abline(h=6.64,col='red') text(31,3.84,expression(paste(alpha==5,%)),pos=3) text(31,6.64,expression(paste(alpha==1,%)),pos=3) 1) I don't know how to specify the margins. I have written it in the code but it is not working. 2) I want the value of alph=5% at the right end of the line but it is almost in the left side and sometimes in the right side when I use the same code for drawing another barplot. I appreciate any comments about these problems. Thanks, Mohsen [[alternative HTML version deleted]] __ 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. -- = David Barron Said Business School University of Oxford Park End Street Oxford OX1 1HP __ 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
On Sat, 2006-10-14 at 23:52 -0400, Mohsen Jafarikia wrote: Hello everyone, I have the following program to draw a barplot. MP-read.table(file='AR.out') names(MP)-c('BN','BL','LR','Q') Graph- barplot(MP$LR, main='LR Value', col='orange', border='black', space= 0.05, width=(MP$BL), xlab='Length', ylab='LR each') axis(1, at=Graph, sprintf('%0.2f',MP$BL)) mtext(1, at=Graph, text=sprintf('%0.2f',MP$Q), line=2) mtext(1, at=par('usr')[1], text='BL', line=1) mtext(1, at=par('usr')[1], text='Var', line=2) abline(h=3.841,col='blue') abline(h=6.635,col='red') I have two more questions about the graph that I have: 1) I want to write the 'Q' only when it is not equal to zero. 2) I would like to change the bars when 'Q' is not zero. For example, from orange to green. I would appreciate your input to this question. Thanks, Mohsen It would be helpful to have the data that you are working with so that we can provide each other a working example. However, here are some hints: 1. mtext(1, at = Graph, text = ifelse(MP$Q != 0, sprintf('%0.2f',MP$Q), ), line=2) 2. cols - ifelse(MP$Q != 0, orange, green) barplot(..., col = cols, ...) See ?ifelse HTH, Marc Schwartz __ 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
Hello again, Thanks for answering my questions. If my program is now: pdf('Test.pdf') BL-c(1.97,8.04,2.54,10.53,4.85,1.73) LR-c(0.85,0.86,8.33,04.18,6.26,2.40) Q-c(0.00,0.00,1.92,01.92,4.48,0.00) cols - ifelse(Q!=0, orange, green) Graph- barplot(LR, main='LR Value',col=cols, border='black', space=0.05, width=(BL), xlab='Length', ylab='LR block') axis(1, at=Graph, sprintf('%0.2f',BL)) mtext(1, at=Graph, text=ifelse(Q!=0, sprintf('%0.2f',Q), ), line=2) mtext(1, at=par('usr')[1], text='BL', line=1) mtext(1, at=par('usr')[1], text='Var', line=2) abline(h=3.8, col='blue')I want to add alpha=5% at the end of this line And now I want to write alpha=5% at the end of the line that I have on my graph. Thanks, Mohsen On 10/15/06, Marc Schwartz [EMAIL PROTECTED] wrote: On Sat, 2006-10-14 at 23:52 -0400, Mohsen Jafarikia wrote: Hello everyone, I have the following program to draw a barplot. MP-read.table(file='AR.out') names(MP)-c('BN','BL','LR','Q') Graph- barplot(MP$LR, main='LR Value', col='orange', border='black', space= 0.05, width=(MP$BL), xlab='Length', ylab='LR each') axis(1, at=Graph, sprintf('%0.2f',MP$BL)) mtext(1, at=Graph, text=sprintf('%0.2f',MP$Q), line=2) mtext(1, at=par('usr')[1], text='BL', line=1) mtext(1, at=par('usr')[1], text='Var', line=2) abline(h= 3.841,col='blue') abline(h=6.635,col='red') I have two more questions about the graph that I have: 1) I want to write the 'Q' only when it is not equal to zero. 2) I would like to change the bars when 'Q' is not zero. For example, from orange to green. I would appreciate your input to this question. Thanks, Mohsen It would be helpful to have the data that you are working with so that we can provide each other a working example. However, here are some hints: 1. mtext(1, at = Graph, text = ifelse(MP$Q != 0, sprintf('%0.2f',MP$Q), ), line=2) 2. cols - ifelse(MP$Q != 0, orange, green) barplot(..., col = cols, ...) See ?ifelse HTH, Marc Schwartz [[alternative HTML version deleted]] __ 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
Try adding text(31,3.8,expression(paste(alpha==5,%)),pos=3) On 15/10/06, Mohsen Jafarikia [EMAIL PROTECTED] wrote: Hello again, Thanks for answering my questions. If my program is now: pdf('Test.pdf') BL-c(1.97,8.04,2.54,10.53,4.85,1.73) LR-c(0.85,0.86,8.33,04.18,6.26,2.40) Q-c(0.00,0.00,1.92,01.92,4.48,0.00) cols - ifelse(Q!=0, orange, green) Graph- barplot(LR, main='LR Value',col=cols, border='black', space=0.05, width=(BL), xlab='Length', ylab='LR block') axis(1, at=Graph, sprintf('%0.2f',BL)) mtext(1, at=Graph, text=ifelse(Q!=0, sprintf('%0.2f',Q), ), line=2) mtext(1, at=par('usr')[1], text='BL', line=1) mtext(1, at=par('usr')[1], text='Var', line=2) abline(h=3.8, col='blue')I want to add alpha=5% at the end of this line And now I want to write alpha=5% at the end of the line that I have on my graph. Thanks, Mohsen On 10/15/06, Marc Schwartz [EMAIL PROTECTED] wrote: On Sat, 2006-10-14 at 23:52 -0400, Mohsen Jafarikia wrote: Hello everyone, I have the following program to draw a barplot. MP-read.table(file='AR.out') names(MP)-c('BN','BL','LR','Q') Graph- barplot(MP$LR, main='LR Value', col='orange', border='black', space= 0.05, width=(MP$BL), xlab='Length', ylab='LR each') axis(1, at=Graph, sprintf('%0.2f',MP$BL)) mtext(1, at=Graph, text=sprintf('%0.2f',MP$Q), line=2) mtext(1, at=par('usr')[1], text='BL', line=1) mtext(1, at=par('usr')[1], text='Var', line=2) abline(h= 3.841,col='blue') abline(h=6.635,col='red') I have two more questions about the graph that I have: 1) I want to write the 'Q' only when it is not equal to zero. 2) I would like to change the bars when 'Q' is not zero. For example, from orange to green. I would appreciate your input to this question. Thanks, Mohsen It would be helpful to have the data that you are working with so that we can provide each other a working example. However, here are some hints: 1. mtext(1, at = Graph, text = ifelse(MP$Q != 0, sprintf('%0.2f',MP$Q), ), line=2) 2. cols - ifelse(MP$Q != 0, orange, green) barplot(..., col = cols, ...) See ?ifelse HTH, Marc Schwartz [[alternative HTML version deleted]] __ 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. -- = David Barron Said Business School University of Oxford Park End Street Oxford OX1 1HP __ 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 legend position
For example : x=matrix(1:10,2,5) barplot(x,besid=T) legend(topleft, c(left,right), density= c(0,1000)) 2006/10/13, Ingmar Visser [EMAIL PROTECTED]: Dear useRs, I'm trying to create a barplot like so: x=matrix(1:10,2,5) barplot(x,leg=c(left,right),besid=T) The legend is placed in default position topright, however the data are plotted there too. I tried controlling the legend position by adding x=topleft but this results in an error that x matches multiple formal arguments. Leaving out the legend and making a separate call to legend leaves out the colors of bars ... Please advice, Ingmar __ 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. -- David [[alternative HTML version deleted]] __ 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 legend position
Thanks, this could work! However, the legend does not reproduce the color/shading used in the original barplot, are those available somehow? Best, Ingmar From: David Hajage [EMAIL PROTECTED] Date: Fri, 13 Oct 2006 14:11:21 +0200 To: Ingmar Visser [EMAIL PROTECTED] Cc: R-help@stat.math.ethz.ch Subject: Re: [R] Barplot legend position For example : x=matrix(1:10,2,5) barplot(x,besid=T) legend(topleft, c(left,right), density= c(0,1000)) 2006/10/13, Ingmar Visser [EMAIL PROTECTED]: Dear useRs, I'm trying to create a barplot like so: x=matrix(1:10,2,5) barplot(x,leg=c(left,right),besid=T) The legend is placed in default position topright, however the data are plotted there too. I tried controlling the legend position by adding x=topleft but this results in an error that x matches multiple formal arguments. Leaving out the legend and making a separate call to legend leaves out the colors of bars ... Please advice, Ingmar __ R-help@stat.math.ethz.ch mailing list https://stat.ethz.ch/mailman/listinfo/r-help 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. -- David [[alternative HTML version deleted]] __ 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 legend position
e.g.: barplot(x,col=c(lightgrey,darkgrey),besid=T) legend(topleft,c(left,right),fill=c(lightgrey,darkgrey)) try: ?legend and example(legend) for documentation!!! Ingmar Visser schrieb: Thanks, this could work! However, the legend does not reproduce the color/shading used in the original barplot, are those available somehow? Best, Ingmar From: David Hajage [EMAIL PROTECTED] Date: Fri, 13 Oct 2006 14:11:21 +0200 To: Ingmar Visser [EMAIL PROTECTED] Cc: R-help@stat.math.ethz.ch Subject: Re: [R] Barplot legend position For example : x=matrix(1:10,2,5) barplot(x,besid=T) legend(topleft, c(left,right), density= c(0,1000)) __ 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 legend position
--- Ingmar Visser [EMAIL PROTECTED] wrote: Thanks, this could work! However, the legend does not reproduce the color/shading used in the original barplot, are those available somehow? Best, Ingmar ?legend Try x=matrix(1:10,2,5) barplot(x,besid=T, col=c(red,blue)) legend(topleft, c(left,right), fill=c(red,blue)) From: David Hajage [EMAIL PROTECTED] Date: Fri, 13 Oct 2006 14:11:21 +0200 To: Ingmar Visser [EMAIL PROTECTED] Cc: R-help@stat.math.ethz.ch Subject: Re: [R] Barplot legend position For example : x=matrix(1:10,2,5) barplot(x,besid=T) legend(topleft, c(left,right), density= c(0,1000)) 2006/10/13, Ingmar Visser [EMAIL PROTECTED]: Dear useRs, I'm trying to create a barplot like so: x=matrix(1:10,2,5) barplot(x,leg=c(left,right),besid=T) The legend is placed in default position topright, however the data are plotted there too. I tried controlling the legend position by adding x=topleft but this results in an error that x matches multiple formal arguments. Leaving out the legend and making a separate call to legend leaves out the colors of bars ... Please advice, Ingmar __ R-help@stat.math.ethz.ch mailing list https://stat.ethz.ch/mailman/listinfo/r-help 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. -- David [[alternative HTML version deleted]] __ 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
Mohsen, I had not seen a reply to your follow up yet and I have been consumed in meetings and on phone calls. On your first question, add two additional lines of code: BL - c(36.35, 36.91, 25.70, 34.38, 5.32) LR - c(1.00, 4.00, 6.00, 3.00, 0.50) Q - c(1.92, 0.00, 0.00, 1.92, 0.00) # Get the bar midpoints in 'mp' mp - barplot(LR, main='LR Value', col='orange', border='black', space=0.05, width=(BL), xlab='Length', ylab='LR') # Write the LR and Q values below the bar midpoints mtext(1, at = mp, text = sprintf(%.1f, LR), line = 1) mtext(1, at = mp, text = sprintf(%.1f, Q), line = 0) # Write labels at minimum value of X axis mtext(1, at = par(usr)[1], text = LR, line = 1) mtext(1, at = par(usr)[1], text = Q, line = 0) See ?par for more information. With respect to adding some sort of curve fit/density plot to your data, it is not clear to me what the data represents, as the x axis does not appear to be monotonic in Q (other than the bar midpoints) and the y axis values do not appear to be counts. If you have the original vector of data, you may be better off with a histogram rather than a barplot, since the histogram will enable a common density area within the bars (ie. the area of the bars = 1.0) over which you can then draw a normal density curve. This general approach was recently covered here: https://stat.ethz.ch/pipermail/r-help/2006-September/113686.html and there are similar examples in the archives. See ?hist and ?truehist in the MASS package. HTH, Marc Schwartz On Mon, 2006-10-02 at 16:42 -0400, Mohsen Jafarikia wrote: Thanks for your response. I just have two more questions: 1) I don't know how to write the titles of the LR and Q behind their lines of values (at the bottom of the graph). I tried to write like text = sprintf(LR%.1f, LR)... but it writes 'LR' behind all values while I only want it once at the beginning of the line while all the LR and Q values are still in the mid points of bars. 2) I would like a line which connects the mid points of each bar to be like a density function (or regression) line which is not sharp like what I have now. I tried to write density in the code but it tells Error in xy.coords(x, y) : 'x' and 'y' lengths differ I appreciate any comment about these questions Thanks, Mohsen On 10/2/06, Marc Schwartz (via MN) [EMAIL PROTECTED] wrote: On Mon, 2006-10-02 at 11:14 -0400, Mohsen Jafarikia wrote: Hello, I have used the following data to draw my barplot: BL LRQ 36.351.00 1.92 36.914.00 0.00 25.706.00 0.00 34.383.00 1.92 05.320.50 0.00 BL-c(36.35, 36.91, 25.70, 34.38, 05.32) LR-c(1.00, 4.00, 6.00, 3.00, 0.50) Q-(1.92, 0.00, 0.00, 1.92, 0.00) barplot(dt$LR, main='LR Value', col='orange', border='black', space= 0.05, width=(dt$BL), xlab='Length', ylab='LR') axis(1) I would like to do the following things that I don't know how to do it: 1) Writing the value of each 'BL' on my X axis. 2) Writing the value of 'Q' on the bottom of X axis. 3) Draw a line on the bars which connects the 'LR' values. I appreciate your comments. Thanks, Mohsen I'm not sure if I am getting this completely correct, but is this what you want? BL - c(36.35, 36.91, 25.70, 34.38, 5.32) LR - c(1.00, 4.00, 6.00, 3.00, 0.50) Q - c(1.92, 0.00, 0.00, 1.92, 0.00) # Get the bar midpoints in 'mp' mp - barplot(LR, main='LR Value', col='orange', border='black', space=0.05, width=(BL), xlab='Length', ylab='LR') # Write the LR and Q values below the bar midpoints mtext(1, at = mp, text = sprintf(%.1f, LR), line = 1) mtext(1, at = mp, text = sprintf(%.1f, Q), line = 0) # Now connect the LR values across the bars lines(mp, LR) See ?barplot, ?mtext, ?sprintf and ?lines HTH, Marc Schwartz __ 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
On Mon, 2006-10-02 at 11:14 -0400, Mohsen Jafarikia wrote: Hello, I have used the following data to draw my barplot: BL LRQ 36.351.00 1.92 36.914.00 0.00 25.706.00 0.00 34.383.00 1.92 05.320.50 0.00 BL-c(36.35, 36.91, 25.70, 34.38, 05.32) LR-c(1.00, 4.00, 6.00, 3.00, 0.50) Q-(1.92, 0.00, 0.00, 1.92, 0.00) barplot(dt$LR, main='LR Value', col='orange', border='black', space=0.05, width=(dt$BL), xlab='Length', ylab='LR') axis(1) I would like to do the following things that I don't know how to do it: 1) Writing the value of each 'BL' on my X axis. 2) Writing the value of 'Q' on the bottom of X axis. 3) Draw a line on the bars which connects the 'LR' values. I appreciate your comments. Thanks, Mohsen I'm not sure if I am getting this completely correct, but is this what you want? BL - c(36.35, 36.91, 25.70, 34.38, 5.32) LR - c(1.00, 4.00, 6.00, 3.00, 0.50) Q - c(1.92, 0.00, 0.00, 1.92, 0.00) # Get the bar midpoints in 'mp' mp - barplot(LR, main='LR Value', col='orange', border='black', space=0.05, width=(BL), xlab='Length', ylab='LR') # Write the LR and Q values below the bar midpoints mtext(1, at = mp, text = sprintf(%.1f, LR), line = 1) mtext(1, at = mp, text = sprintf(%.1f, Q), line = 0) # Now connect the LR values across the bars lines(mp, LR) See ?barplot, ?mtext, ?sprintf and ?lines HTH, Marc Schwartz __ 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
Thanks for your response. I just have two more questions: 1) I don't know how to write the titles of the LR and Q behind their lines of values (at the bottom of the graph). I tried to write like text = sprintf(LR%.1f, LR)... but it writes 'LR' behind all values while I only want it once at the beginning of the line while all the LR and Q values are still in the mid points of bars. 2) I would like a line which connects the mid points of each bar to be like a density function (or regression) line which is not sharp like what I have now. I tried to write density in the code but it tells Error in xy.coords(x, y) : 'x' and 'y' lengths differ I appreciate any comment about these questions Thanks, Mohsen On 10/2/06, Marc Schwartz (via MN) [EMAIL PROTECTED] wrote: On Mon, 2006-10-02 at 11:14 -0400, Mohsen Jafarikia wrote: Hello, I have used the following data to draw my barplot: BL LRQ 36.351.00 1.92 36.914.00 0.00 25.706.00 0.00 34.383.00 1.92 05.320.50 0.00 BL-c(36.35, 36.91, 25.70, 34.38, 05.32) LR-c(1.00, 4.00, 6.00, 3.00, 0.50) Q-(1.92, 0.00, 0.00, 1.92, 0.00) barplot(dt$LR, main='LR Value', col='orange', border='black', space= 0.05, width=(dt$BL), xlab='Length', ylab='LR') axis(1) I would like to do the following things that I don't know how to do it: 1) Writing the value of each 'BL' on my X axis. 2) Writing the value of 'Q' on the bottom of X axis. 3) Draw a line on the bars which connects the 'LR' values. I appreciate your comments. Thanks, Mohsen I'm not sure if I am getting this completely correct, but is this what you want? BL - c(36.35, 36.91, 25.70, 34.38, 5.32) LR - c(1.00, 4.00, 6.00, 3.00, 0.50) Q - c(1.92, 0.00, 0.00, 1.92, 0.00) # Get the bar midpoints in 'mp' mp - barplot(LR, main='LR Value', col='orange', border='black', space=0.05, width=(BL), xlab='Length', ylab='LR') # Write the LR and Q values below the bar midpoints mtext(1, at = mp, text = sprintf(%.1f, LR), line = 1) mtext(1, at = mp, text = sprintf(%.1f, Q), line = 0) # Now connect the LR values across the bars lines(mp, LR) See ?barplot, ?mtext, ?sprintf and ?lines HTH, Marc Schwartz -- Mohsen Jafarikia Department of Animal and Poultry Science University of Guelph Phone: (519) 824-4120 ext.58353 [[alternative HTML version deleted]] __ 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: different colors for the bar and the strips
On Thu, 2006-09-07 at 06:18 -0500, Hao Chen wrote: Hi, I am using barplot and would like to know if it is possible to have bars filled with one color while use a different color for the shading lines. The following code colors the shading lines, leaving the bars in white: barplot(1:5, col=c(1:5), density=c(1:5)*5) while the colors are applied to the bars when density is removed. barplot(1:5, col=c(1:5)) I did check ?barplot and found the following: col: a vector of colors for the bars or bar components. Thanks, Hao Note the key word 'or' in the description of the 'col' argument. You need to make two separate calls to barplot(). The first using the fill colors, then the second using the shading lines AND setting 'add = TRUE', so that the second plot overwrites the first without clearing the plot device. barplot(1:5, col=c(1:5)) barplot(1:5, col = black, density=c(1:5), add = TRUE) Just be sure that any other arguments, such as axis limits, are identical between the two calls. HTH, Marc Schwartz __ 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: different colors for the bar and the strips
Hello Marc Schwartz On Thu, Sep 07, 2006 at 07:54:05AM -0500, Marc Schwartz wrote: On Thu, 2006-09-07 at 06:18 -0500, Hao Chen wrote: Hi, I am using barplot and would like to know if it is possible to have bars filled with one color while use a different color for the shading lines. The following code colors the shading lines, leaving the bars in white: barplot(1:5, col=c(1:5), density=c(1:5)*5) while the colors are applied to the bars when density is removed. barplot(1:5, col=c(1:5)) I did check ?barplot and found the following: col: a vector of colors for the bars or bar components. Thanks, Hao Note the key word 'or' in the description of the 'col' argument. You need to make two separate calls to barplot(). The first using the fill colors, then the second using the shading lines AND setting 'add = TRUE', so that the second plot overwrites the first without clearing the plot device. barplot(1:5, col=c(1:5)) barplot(1:5, col = black, density=c(1:5), add = TRUE) Just be sure that any other arguments, such as axis limits, are identical between the two calls. HTH, Marc Schwartz Thank you very much for your help. It works but only in the order as you put it, since the following code only shows the color, but not the shading lines: barplot(1:5, col = black, density=c(1:5)) barplot(1:5, col=c(1:5), add = TRUE) Hao Chen --- Mining PubMed: http://www.chilibot.net - __ 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: different colors for the bar and the strips
On Thu, 2006-09-07 at 12:14 -0500, Hao Chen wrote: Hello Marc Schwartz On Thu, Sep 07, 2006 at 07:54:05AM -0500, Marc Schwartz wrote: On Thu, 2006-09-07 at 06:18 -0500, Hao Chen wrote: Hi, I am using barplot and would like to know if it is possible to have bars filled with one color while use a different color for the shading lines. The following code colors the shading lines, leaving the bars in white: barplot(1:5, col=c(1:5), density=c(1:5)*5) while the colors are applied to the bars when density is removed. barplot(1:5, col=c(1:5)) I did check ?barplot and found the following: col: a vector of colors for the bars or bar components. Thanks, Hao Note the key word 'or' in the description of the 'col' argument. You need to make two separate calls to barplot(). The first using the fill colors, then the second using the shading lines AND setting 'add = TRUE', so that the second plot overwrites the first without clearing the plot device. barplot(1:5, col=c(1:5)) barplot(1:5, col = black, density=c(1:5), add = TRUE) Just be sure that any other arguments, such as axis limits, are identical between the two calls. HTH, Marc Schwartz Thank you very much for your help. It works but only in the order as you put it, since the following code only shows the color, but not the shading lines: barplot(1:5, col = black, density=c(1:5)) barplot(1:5, col=c(1:5), add = TRUE) Hao Chen That is correct. The sequence is important, as the shading lines are drawn with a transparent background, enabling the original color to be seen. Reversing the order, you are overplotting the shading lines with opaque colored rectangles. Hence, the lines are lost. HTH, Marc __ 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
barplot(t(sapply(split(z1[,1:8], z1$V9),colSums)), beside=T) --- 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 --- Muhammad Subianto a écrit : Dear all, I have a dataset. I want to make barplot from this data. Zero1 - V1 V2 V3 V4 V5 V6 V7 V8 V9 1 1 0 0 0 1 0 0 0 Positive 2 0 0 1 0 1 0 1 1 Negative 3 0 0 1 0 0 0 1 1 Positive 4 0 1 0 1 1 1 0 1 Negative 5 0 0 1 0 1 1 0 0 Positive 6 0 1 0 0 1 1 1 1 Negative 7 1 0 1 1 1 1 1 1 Negative 8 0 0 0 0 1 0 0 1 Negative 9 0 1 1 1 1 0 0 1 Negative 10 0 0 0 1 1 0 1 0 Positive 11 0 0 0 0 1 0 0 1 Negative 12 0 0 1 1 1 1 1 0 Positive 13 0 1 1 0 1 1 1 1 Negative z1 - read.table(textConnection(Zero1), header=TRUE) z1 str(z1) A simple way I can use mosaic plot mosaicplot(table(z1)) library(vcd) mosaic(table(z1)) I have tried to learn ?xtabs ?table and ?ftable but I can't figure out. I need a barplot for all variables and the result maybe like | | | | | | | | | || | | |pos|neg| |pos|neg||pos|neg| | | | | | || | | - -- v1v2v3 v7 v8 Thanks you for any helps. Regards, Muhammad Subianto __ 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
Muhammad Subianto wrote: ... I have tried to learn ?xtabs ?table and ?ftable but I can't figure out. I need a barplot for all variables and the result maybe like | | | | | | | | | || | | |pos|neg| |pos|neg||pos|neg| | | | | | || | | - -- v1v2v3 v7 v8 barplot(sapply(z1[1:8],by,z1[9],sum),beside=TRUE) Jim __ 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 - thanks
Dear all, Many Thanks to Jacques VESLOT and Jim Lemon for their helps. Best, Muhammad Subianto #Jacques VESLOT barplot(t(sapply(split(z1[,1:8], z1$V9),colSums)), beside=T) #Jim Lemon barplot(sapply(z1[1:8],by,z1[9],sum),beside=TRUE) On this day 30/08/2006 11:43, Muhammad Subianto wrote: Dear all, I have a dataset. I want to make barplot from this data. Zero1 - V1 V2 V3 V4 V5 V6 V7 V8 V9 1 1 0 0 0 1 0 0 0 Positive 2 0 0 1 0 1 0 1 1 Negative 3 0 0 1 0 0 0 1 1 Positive 4 0 1 0 1 1 1 0 1 Negative 5 0 0 1 0 1 1 0 0 Positive 6 0 1 0 0 1 1 1 1 Negative 7 1 0 1 1 1 1 1 1 Negative 8 0 0 0 0 1 0 0 1 Negative 9 0 1 1 1 1 0 0 1 Negative 10 0 0 0 1 1 0 1 0 Positive 11 0 0 0 0 1 0 0 1 Negative 12 0 0 1 1 1 1 1 0 Positive 13 0 1 1 0 1 1 1 1 Negative z1 - read.table(textConnection(Zero1), header=TRUE) z1 str(z1) A simple way I can use mosaic plot mosaicplot(table(z1)) library(vcd) mosaic(table(z1)) I have tried to learn ?xtabs ?table and ?ftable but I can't figure out. I need a barplot for all variables and the result maybe like | | | | | | | | | || | | |pos|neg| |pos|neg||pos|neg| | | | | | || | | - -- v1v2v3 v7 v8 Thanks you for any helps. Regards, Muhammad Subianto __ 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
Try this. First we reduce the data to a frequency matrix and then plot it using classic and then lattice graphics: zm - as.matrix(rowsum(z1[-9], z1[,9])) barplot(zm, beside = TRUE, col = grey.colors(2)) legend(topleft, legend = levels(z1[,9]), fill = grey.colors(2)) library(lattice) barchart(Freq ~ Var2, as.data.frame.table(zm), groups = Var1, origin = 0, auto.key = TRUE) On 8/30/06, Muhammad Subianto [EMAIL PROTECTED] wrote: Dear all, I have a dataset. I want to make barplot from this data. Zero1 - V1 V2 V3 V4 V5 V6 V7 V8 V9 1 1 0 0 0 1 0 0 0 Positive 2 0 0 1 0 1 0 1 1 Negative 3 0 0 1 0 0 0 1 1 Positive 4 0 1 0 1 1 1 0 1 Negative 5 0 0 1 0 1 1 0 0 Positive 6 0 1 0 0 1 1 1 1 Negative 7 1 0 1 1 1 1 1 1 Negative 8 0 0 0 0 1 0 0 1 Negative 9 0 1 1 1 1 0 0 1 Negative 10 0 0 0 1 1 0 1 0 Positive 11 0 0 0 0 1 0 0 1 Negative 12 0 0 1 1 1 1 1 0 Positive 13 0 1 1 0 1 1 1 1 Negative z1 - read.table(textConnection(Zero1), header=TRUE) z1 str(z1) A simple way I can use mosaic plot mosaicplot(table(z1)) library(vcd) mosaic(table(z1)) I have tried to learn ?xtabs ?table and ?ftable but I can't figure out. I need a barplot for all variables and the result maybe like | | | | | | | | | || | | |pos|neg| |pos|neg||pos|neg| | | | | | || | | - -- v1v2v3 v7 v8 Thanks you for any helps. Regards, Muhammad Subianto __ 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
Dear all, To Gabor Grothendieck, (again) thanks you very much for your help. Now, I can play around with lattice package. Best, Muhammad Subianto #Gabor #reduce the data to a frequency matrix and #then plot it using classic and then lattice graphics: zm - as.matrix(rowsum(z1[-9], z1[,9])) barplot(zm, beside = TRUE, col = grey.colors(2)) legend(topleft, legend = levels(z1[,9]), fill = grey.colors(2)) library(lattice) barchart(Freq ~ Var2, as.data.frame.table(zm), groups = Var1, origin = 0, auto.key = TRUE) On this day 30/08/2006 16:18, Gabor Grothendieck wrote: Try this. First we reduce the data to a frequency matrix and then plot it using classic and then lattice graphics: zm - as.matrix(rowsum(z1[-9], z1[,9])) barplot(zm, beside = TRUE, col = grey.colors(2)) legend(topleft, legend = levels(z1[,9]), fill = grey.colors(2)) library(lattice) barchart(Freq ~ Var2, as.data.frame.table(zm), groups = Var1, origin = 0, auto.key = TRUE) On 8/30/06, Muhammad Subianto [EMAIL PROTECTED] wrote: Dear all, I have a dataset. I want to make barplot from this data. Zero1 - V1 V2 V3 V4 V5 V6 V7 V8 V9 1 1 0 0 0 1 0 0 0 Positive 2 0 0 1 0 1 0 1 1 Negative 3 0 0 1 0 0 0 1 1 Positive 4 0 1 0 1 1 1 0 1 Negative 5 0 0 1 0 1 1 0 0 Positive 6 0 1 0 0 1 1 1 1 Negative 7 1 0 1 1 1 1 1 1 Negative 8 0 0 0 0 1 0 0 1 Negative 9 0 1 1 1 1 0 0 1 Negative 10 0 0 0 1 1 0 1 0 Positive 11 0 0 0 0 1 0 0 1 Negative 12 0 0 1 1 1 1 1 0 Positive 13 0 1 1 0 1 1 1 1 Negative z1 - read.table(textConnection(Zero1), header=TRUE) z1 str(z1) A simple way I can use mosaic plot mosaicplot(table(z1)) library(vcd) mosaic(table(z1)) I have tried to learn ?xtabs ?table and ?ftable but I can't figure out. I need a barplot for all variables and the result maybe like | | | | | | | | | || | | |pos|neg| |pos|neg||pos|neg| | | | | | || | | - -- v1v2v3 v7 v8 Thanks you for any helps. Regards, Muhammad Subianto __ 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 dataframes w/ varying dimensions
On Fri, 2006-06-09 at 06:05 -0500, Marc Schwartz wrote: On Fri, 2006-06-09 at 11:26 +0100, Albert Vilella wrote: Hi all, I would like to do a barplot of a dataframe like this one: alfa beta gamma delta qwert 56.5 58.5 56.5 58.5 asdfg 73.0 73.0 43.0 73.0 zxcvb 63.0 63.0 43.0 63.0 yuiop 63.0 63.0 43.0 63.0 with the labels of the rows and columns. I would like to have something that works for dataframes with varying dimensions, and so far I haven't found any way to do it. What would be the best way to do that? Thanks in advance, Albert. barplot() requires the 'height' argument to be a vector or matrix, so you need to coerce the data frame: barplot(as.matrix(DF)) or barplot(as.matrix(DF), beside = TRUE) depending upon the format you prefer. I forgot to note that you will get the colnames(DF) to label the groupings by default, but to get the rownames(DF) as well, you might do that with a legend: barplot(as.matrix(DF), legend.text = rownames(DF), ylim = c(0, max(colSums(DF)) * 1.4)) or barplot(as.matrix(DF), beside = TRUE, legend.text = rownames(DF), ylim = c(0, max(DF) * 1.4)) Note that I have adjusted the range of the y axis in each case to make room for the legend in the upper right hand corner. You would have more flexibility in legend formatting by using legend() separately. See ?legend for more information. HTH, Marc __ 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
Re: [R] barplot dataframes w/ varying dimensions
On Fri, 2006-06-09 at 11:26 +0100, Albert Vilella wrote: Hi all, I would like to do a barplot of a dataframe like this one: alfa beta gamma delta qwert 56.5 58.5 56.5 58.5 asdfg 73.0 73.0 43.0 73.0 zxcvb 63.0 63.0 43.0 63.0 yuiop 63.0 63.0 43.0 63.0 with the labels of the rows and columns. I would like to have something that works for dataframes with varying dimensions, and so far I haven't found any way to do it. What would be the best way to do that? Thanks in advance, Albert. barplot() requires the 'height' argument to be a vector or matrix, so you need to coerce the data frame: barplot(as.matrix(DF)) or barplot(as.matrix(DF), beside = TRUE) depending upon the format you prefer. HTH, Marc Schwartz __ 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
Re: [R] barplot dataframes w/ varying dimensions
Hi something like tab alfa beta gamma delta qwert 56.5 58.5 56.5 58.5 asdfg 73.0 73.0 43.0 73.0 zxcvb 63.0 63.0 43.0 63.0 yuiop 63.0 63.0 43.0 63.0 barplot(as.matrix(tab), beside=T, legend.text=T) HTH Petr On 9 Jun 2006 at 11:26, Albert Vilella wrote: From: Albert Vilella [EMAIL PROTECTED] To: r-help@stat.math.ethz.ch Date sent: Fri, 09 Jun 2006 11:26:26 +0100 Subject:[R] barplot dataframes w/ varying dimensions Send reply to: [EMAIL PROTECTED] mailto:[EMAIL PROTECTED] mailto:[EMAIL PROTECTED] Hi all, I would like to do a barplot of a dataframe like this one: alfa beta gamma delta qwert 56.5 58.5 56.5 58.5 asdfg 73.0 73.0 43.0 73.0 zxcvb 63.0 63.0 43.0 63.0 yuiop 63.0 63.0 43.0 63.0 with the labels of the rows and columns. I would like to have something that works for dataframes with varying dimensions, and so far I haven't found any way to do it. What would be the best way to do that? Thanks in advance, Albert. __ 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 Petr Pikal [EMAIL PROTECTED] __ 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
Re: [R] barplot names.arg
On Mon, 2006-03-06 at 15:40 +0100, Roland Kaiser wrote: How can i set a rotation for the names.arg in barplot? See R FAQ 7.27 How can I create rotated axis labels?: http://cran.r-project.org/doc/FAQ/R-FAQ.html#How-can-I-create-rotated-axis-labels_003f That provides the basic concept, which is easy to use with barplot() along with knowing that barplot() returns the bar midpoints. See the Value section of ?barplot. HTH, Marc Schwartz __ 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
Re: [R] barplot names.arg
Marc Schwartz (via MN) wrote: On Mon, 2006-03-06 at 15:40 +0100, Roland Kaiser wrote: How can i set a rotation for the names.arg in barplot? See R FAQ 7.27 How can I create rotated axis labels?: http://cran.r-project.org/doc/FAQ/R-FAQ.html#How-can-I-create-rotated-axis-labels_003f Interesting That provides the basic concept, which is easy to use with barplot() along with knowing that barplot() returns the bar midpoints. See the Value section of ?barplot. HTH, Marc Schwartz __ 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 __ 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
Re: [R] barplot legend
On Fri, 2005-07-01 at 14:04 +0200, Navarre Sabine wrote: Hi, Is it possible ti put the legend out of a barplot? tanks Sabine I presume that you mean outside the plot region? If so, you can use something like the following: # Adjust the plot margins to make room for the # legend on the right side. See ?par par(mar = c(5, 4, 4, 10) + 0.1) barplot(1:10) box() # Set xpd to allow legend placement outside # plot region. See ?par par(xpd = TRUE) # Left click on the right side of the window where you want # the legend. See ?locator l - locator(1) # Now put the legend where you clicked # See ?legend legend(l$x, l$y, legend = Legend Here) HTH, Marc Schwartz __ 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
Re: [R] barplot and missing values?
Dan Bolser wrote: I want to include missing values in my barplot to get the correct x-axis, for example, x - c(1,2,3,4, 9) y - c(2,4,6,8,18) barplot(y) The above looks wrong because the last height in y should be a long way over. So I want to do something like... x - c(1,2,3,4,5,6,7,8, 9) y - c(2,4,6,8,0,0,0,0,18) barplot(y) However... I am actually using barplot2 to use the log='y' function, so I can't use zero values on a log scale... So I need... x - c(1,2,3,4, 5, 6, 7, 8, 9) y - c(2,4,6,8,NA,NA,NA,NA,18) barplot(y) But that don't work. Actually, it works, at least for me (R-2.1.0, WinNT, but you have not told us your details!). BTW: In the meantime package gregmisc has been superseded by the gregmisc bundle, and later on by a number of packages (such as gtools, gdata, ...). Your setup seems to be rather outdated. Uwe Ligges Am I missing something? To avoid confusion here is my data... dat.y.plot [,1] [,2] [,3] [,4] [,5] [,6] [,7] [,8] [,9] [,10] [,11] [,12] Ho 653 80 132 10 343 1007 2 7 7 He 139 56 696 243 1132 1 2 6 attr(,names) [1] 2 3 4 5 6 7 8 9 10 11 12 12 [13] NANANANANANANANANANANANA And here is what I call... barplot(dat.y.plot, ylim=c(0,max(dat.y.plot + 50)), # I don't like the default beside=T, names.arg=c('2','3','4','5','6','7','8','9','10','11','12','12'), cex.axis=1.5, cex.names=1.5, legend=T ) Which is fine (except I don't know why I still need names.arg). Then I try... library(gregmisc) barplot2(dat.y.plot+1, log='y', beside=T, names.arg=c('2','3','4','5','6','7','8','9','10','11','12','12'), cex.axis=1.5, cex.names=1.5, legend=T ) Which fails because of the zero. If I try ... dat.y.plot[dat.y.plot==0] - NA It fails because of the NA. Any suggestions? __ 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 __ 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
Re: [R] barplot and missing values?
On Sat, 4 Jun 2005, Uwe Ligges wrote: Dan Bolser wrote: I want to include missing values in my barplot to get the correct x-axis, for example, x - c(1,2,3,4, 9) y - c(2,4,6,8,18) barplot(y) The above looks wrong because the last height in y should be a long way over. So I want to do something like... x - c(1,2,3,4,5,6,7,8, 9) y - c(2,4,6,8,0,0,0,0,18) barplot(y) However... I am actually using barplot2 to use the log='y' function, so I can't use zero values on a log scale... So I need... x - c(1,2,3,4, 5, 6, 7, 8, 9) y - c(2,4,6,8,NA,NA,NA,NA,18) barplot(y) But that don't work. Actually, it works, at least for me (R-2.1.0, WinNT, but you have not told us your details!). BTW: In the meantime package gregmisc has been superseded by the gregmisc bundle, and later on by a number of packages (such as gtools, gdata, ...). Your setup seems to be rather outdated. yeah :( R 2.0.0 (2004-10-04). I will upgrade to 2.1.0 (latest stable?) Instead of gregmisc what should I use to get barplot2? Will barplot() ever become barplot2() I will try upgrading Dan. Uwe Ligges Am I missing something? To avoid confusion here is my data... dat.y.plot [,1] [,2] [,3] [,4] [,5] [,6] [,7] [,8] [,9] [,10] [,11] [,12] Ho 653 80 132 10 343 1007 2 7 7 He 139 56 696 243 1132 1 2 6 attr(,names) [1] 2 3 4 5 6 7 8 9 10 11 12 12 [13] NANANANANANANANANANANANA And here is what I call... barplot(dat.y.plot, ylim=c(0,max(dat.y.plot + 50)), # I don't like the default beside=T, names.arg=c('2','3','4','5','6','7','8','9','10','11','12','12'), cex.axis=1.5, cex.names=1.5, legend=T ) Which is fine (except I don't know why I still need names.arg). Then I try... library(gregmisc) barplot2(dat.y.plot+1, log='y', beside=T, names.arg=c('2','3','4','5','6','7','8','9','10','11','12','12'), cex.axis=1.5, cex.names=1.5, legend=T ) Which fails because of the zero. If I try ... dat.y.plot[dat.y.plot==0] - NA It fails because of the NA. Any suggestions? __ 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 __ 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
Re: [R] barplot and missing values?
Dan Bolser wrote: On Sat, 4 Jun 2005, Uwe Ligges wrote: Dan Bolser wrote: I want to include missing values in my barplot to get the correct x-axis, for example, x - c(1,2,3,4, 9) y - c(2,4,6,8,18) barplot(y) The above looks wrong because the last height in y should be a long way over. So I want to do something like... x - c(1,2,3,4,5,6,7,8, 9) y - c(2,4,6,8,0,0,0,0,18) barplot(y) However... I am actually using barplot2 to use the log='y' function, so I can't use zero values on a log scale... So I need... x - c(1,2,3,4, 5, 6, 7, 8, 9) y - c(2,4,6,8,NA,NA,NA,NA,18) barplot(y) But that don't work. Actually, it works, at least for me (R-2.1.0, WinNT, but you have not told us your details!). BTW: In the meantime package gregmisc has been superseded by the gregmisc bundle, and later on by a number of packages (such as gtools, gdata, ...). Your setup seems to be rather outdated. yeah :( R 2.0.0 (2004-10-04). Hmm. I just tested with R-1.9.1, and your last example even works with that one... I will upgrade to 2.1.0 (latest stable?) Instead of gregmisc what should I use to get barplot2? package gplots You example y is also handled perfectly well by barplot2() on my system, BTW. Uwe Ligges Will barplot() ever become barplot2() I will try upgrading Dan. Uwe Ligges Am I missing something? To avoid confusion here is my data... dat.y.plot [,1] [,2] [,3] [,4] [,5] [,6] [,7] [,8] [,9] [,10] [,11] [,12] Ho 653 80 132 10 343 1007 2 7 7 He 139 56 696 243 1132 1 2 6 attr(,names) [1] 2 3 4 5 6 7 8 9 10 11 12 12 [13] NANANANANANANANANANANANA And here is what I call... barplot(dat.y.plot, ylim=c(0,max(dat.y.plot + 50)), # I don't like the default beside=T, names.arg=c('2','3','4','5','6','7','8','9','10','11','12','12'), cex.axis=1.5, cex.names=1.5, legend=T ) Which is fine (except I don't know why I still need names.arg). Then I try... library(gregmisc) barplot2(dat.y.plot+1, log='y', beside=T, names.arg=c('2','3','4','5','6','7','8','9','10','11','12','12'), cex.axis=1.5, cex.names=1.5, legend=T ) Which fails because of the zero. If I try ... dat.y.plot[dat.y.plot==0] - NA It fails because of the NA. Any suggestions? __ 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 __ 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
Re: [R] barplot and missing values?
On Sat, 4 Jun 2005, Uwe Ligges wrote: Dan Bolser wrote: On Sat, 4 Jun 2005, Uwe Ligges wrote: Dan Bolser wrote: I want to include missing values in my barplot to get the correct x-axis, for example, x - c(1,2,3,4, 9) y - c(2,4,6,8,18) barplot(y) The above looks wrong because the last height in y should be a long way over. So I want to do something like... x - c(1,2,3,4,5,6,7,8, 9) y - c(2,4,6,8,0,0,0,0,18) barplot(y) However... I am actually using barplot2 to use the log='y' function, so I can't use zero values on a log scale... So I need... x - c(1,2,3,4, 5, 6, 7, 8, 9) y - c(2,4,6,8,NA,NA,NA,NA,18) barplot(y) But that don't work. Actually, it works, at least for me (R-2.1.0, WinNT, but you have not told us your details!). BTW: In the meantime package gregmisc has been superseded by the gregmisc bundle, and later on by a number of packages (such as gtools, gdata, ...). Your setup seems to be rather outdated. yeah :( R 2.0.0 (2004-10-04). Hmm. I just tested with R-1.9.1, and your last example even works with that one... I will upgrade to 2.1.0 (latest stable?) Instead of gregmisc what should I use to get barplot2? package gplots You example y is also handled perfectly well by barplot2() on my system, BTW. This must be because of the log='y' option that I am using here. y - c(2,4,6,8,NA,NA,NA,NA,18) barplot2(y,log='y') Above fails. I appreciate that what I am trying to do is somewhat artificial (handle zero values on a log scale), but it does reflect the data I have. I tried plot(..., type='h'), but that dosn't do the beside=T stuff that I want to do. I am now trying things like... barplot2( dat.y.plot + 0.11, # Dirty hack offset=-0.1, # xpd=F, # log='y', beside=T ) Which looks messy. Any way to cleanly handle NA values with barplot2 on a log scale (log='y')? Thanks for your help :) Uwe Ligges Will barplot() ever become barplot2() I will try upgrading Dan. Uwe Ligges Am I missing something? To avoid confusion here is my data... dat.y.plot [,1] [,2] [,3] [,4] [,5] [,6] [,7] [,8] [,9] [,10] [,11] [,12] Ho 653 80 132 10 343 1007 2 7 7 He 139 56 696 243 1132 1 2 6 attr(,names) [1] 2 3 4 5 6 7 8 9 10 11 12 12 [13] NANANANANANANANANANANANA And here is what I call... barplot(dat.y.plot, ylim=c(0,max(dat.y.plot + 50)), # I don't like the default beside=T, names.arg=c('2','3','4','5','6','7','8','9','10','11','12','12'), cex.axis=1.5, cex.names=1.5, legend=T ) Which is fine (except I don't know why I still need names.arg). Then I try... library(gregmisc) barplot2(dat.y.plot+1, log='y', beside=T, names.arg=c('2','3','4','5','6','7','8','9','10','11','12','12'), cex.axis=1.5, cex.names=1.5, legend=T ) Which fails because of the zero. If I try ... dat.y.plot[dat.y.plot==0] - NA It fails because of the NA. Any suggestions? __ 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 __ 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
Re: [R] barplot and missing values?
Dan Bolser wrote: [all previous stuff deleted] I see, what comes out of this longish thread is: - barplot() and barplot2() both have deficiencies for you particular examples, so it is time to provide patches for both barplot() and barplot2() (for the latter, you might want to contact the package maintainer as well) ... - Please provide *reproducible* examples (yours was not, because log='y' was missing). Hence the relevant example we were obviously talking about is: y - c(2,4,6,8,NA,NA,NA,NA,18) barplot(y, log=y) library(gplots) barplot2(y, log=y) Uwe Ligges __ 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
Re: [R] barplot and missing values?
On Sat, 2005-06-04 at 14:50 +0100, Dan Bolser wrote: snip This must be because of the log='y' option that I am using here. y - c(2,4,6,8,NA,NA,NA,NA,18) barplot2(y,log='y') Above fails. I appreciate that what I am trying to do is somewhat artificial (handle zero values on a log scale), but it does reflect the data I have. I tried plot(..., type='h'), but that dosn't do the beside=T stuff that I want to do. I am now trying things like... barplot2( dat.y.plot + 0.11, # Dirty hack offset=-0.1, # xpd=F, # log='y', beside=T ) Which looks messy. Any way to cleanly handle NA values with barplot2 on a log scale (log='y')? snip Dan, You are actually close in the above example, using the 'offset' argument. In this case, you still cannot use NAs, since their value is unknown and so must set these elements to zero. Then using a small offset value, you can adjust the base value of the y axis so that it is just above zero. This should result in a minimal shift of the bar values above their actual values and should not materially affect the plot's representation of the data. Something like the following should work: y - c(2, 4, 6, 8, NA, NA, NA, NA, 18) y [1] 2 4 6 8 NA NA NA NA 18 y[is.na(y)] - 0 y [1] 2 4 6 8 0 0 0 0 18 barplot2(y, log = y, offset = 0.01, las = 2) Note also that if you follow the above with: box() The residual bars from the (0 + 0.01) values are covered with the plot region box, if that is an issue for you. This is still something of a hack, but it is a little cleaner. The key of course is to avoid the use of a bar value of log(x), where x = 0. Selecting the proper offset value based upon your actual data is important so as to minimally affect the values visually. HTH, Marc Schwartz __ 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
Re: [R] barplot and missing values?
On Sat, 4 Jun 2005, Marc Schwartz wrote: On Sat, 2005-06-04 at 14:50 +0100, Dan Bolser wrote: snip This must be because of the log='y' option that I am using here. y - c(2,4,6,8,NA,NA,NA,NA,18) barplot2(y,log='y') Above fails. I appreciate that what I am trying to do is somewhat artificial (handle zero values on a log scale), but it does reflect the data I have. I tried plot(..., type='h'), but that dosn't do the beside=T stuff that I want to do. I am now trying things like... barplot2( dat.y.plot + 0.11, # Dirty hack offset=-0.1, # xpd=F, # log='y', beside=T ) Which looks messy. Any way to cleanly handle NA values with barplot2 on a log scale (log='y')? snip Dan, You are actually close in the above example, using the 'offset' argument. In this case, you still cannot use NAs, since their value is unknown and so must set these elements to zero. Then using a small offset value, you can adjust the base value of the y axis so that it is just above zero. This should result in a minimal shift of the bar values above their actual values and should not materially affect the plot's representation of the data. Something like the following should work: y - c(2, 4, 6, 8, NA, NA, NA, NA, 18) y [1] 2 4 6 8 NA NA NA NA 18 y[is.na(y)] - 0 y [1] 2 4 6 8 0 0 0 0 18 barplot2(y, log = y, offset = 0.01, las = 2) Note also that if you follow the above with: box() The residual bars from the (0 + 0.01) values are covered with the plot region box, if that is an issue for you. Actually it looks a bit strange (I guess you didn't check it?) - I see what is happening. It isn't much different from... barplot2(y+0.01, log = y,las = 1) Which is the essence of the fix, but all that bar (on a log scale) between 1 and 0.1 and 0.01 is as big as 1 to 10, which is a bit artificial. My previous fix looks best now I check it with the example ... y y [1] 2 4 6 8 0 0 0 0 18 barplot2( y + 0.11, ylim=c(1,max(y)), offset = -0.10, log='y', xpd=F ) box() Looks like the above is what I need :) Thanks for teh help - its reasuring to see similar fixes :) This is still something of a hack, but it is a little cleaner. The key of course is to avoid the use of a bar value of log(x), where x = 0. Selecting the proper offset value based upon your actual data is important so as to minimally affect the values visually. HTH, Marc Schwartz __ 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
Re: [R] Barplot and colors for legend
Werner Wernersen wrote: Hi all! One quick question: How do I get the standard colors used by barplot? I have some stacked bars and would like to add a horizontal legend via legend() but I don't know how to find the colors for the fills of the legend points. Thanks! Werner Type barplot.default and read the code: for a vector: grey, for a matrix: grey(seq(0.3^2.2, 0.9^2.2, length = nrow(height))^(1/2.2)) Uwe Ligges __ 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
Re: [R] Barplot and colors for legend
On Mon, 18 Apr 2005 16:48:42 +0200 Uwe Ligges wrote: Werner Wernersen wrote: Hi all! One quick question: How do I get the standard colors used by barplot? I have some stacked bars and would like to add a horizontal legend via legend() but I don't know how to find the colors for the fills of the legend points. Thanks! Werner Type barplot.default and read the code: for a vector: grey, for a matrix: grey(seq(0.3^2.2, 0.9^2.2, length = nrow(height))^(1/2.2)) This must be an old version of R ;-) In R 2.1.0, there is a function gray.colors() which creates a vector of gamma-corrected gray colors (and is used in barplot.default). Best, Z Uwe Ligges __ 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 __ 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
RE: [R] Barplot and colors for legend
Well I don't know how I can live with myself. I guess I can't wait for the site to mirror itself in case someone thinks I'm yesterday's man. ;-) -Original Message- From: [EMAIL PROTECTED] [mailto:[EMAIL PROTECTED] Behalf Of Achim Zeileis Sent: Monday, 18 April 2005 10:56 PM ... Subject: Re: [R] Barplot and colors for legend ... This must be an old version of R ;-) ... Tom Mulholland Perth, WA, Australia. ,-_|\ / \ ?_,-._/ v __ 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
Re: [R] barplot usage
On Wed, 2005-04-13 at 19:05 -0300, Antonio Olinto wrote: Hi, Im trying to make a barplot with the following dataframe, with information on relative frequency per sediment type (ST) for some species: Species ST1 ST2 ST3 SP_A 10 6030 ... At x-axis are (should be ...) the species names and at y-axis the frequency per sediment, in stacked bars. I tried to use barplot command but with no results. Could anyone help me on this? Thanks in advance, Samantha You could use something like the following (presuming that your data is a data frame called 'df'): barplot(t(df[2:4]), names.arg = as.character(df$Species)) Note that the row values that you have (excluding the Species name) need to be rotated 90 degrees as follows: t(df[2:4]) 1 ... ST1 10 ... ST2 60 ... ST3 30 ... In this case, each column represents the segments of each stacked bar (or if you set 'beside = TRUE', the individual bars in a group of bars) Then the labels below each bar in the plot come from the df$Species column. I used as.character(df$Species) presuming that this column might be a factor. If not, you can eliminate the use of as.character() here. HTH, Marc Schwartz __ 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
Re: [R] Barplot - Can't figure it out
Hi If I understand correctly barplot(rbind(table(x), table(y)), beside=T) does what you want. Cheers Petr On 18 Feb 2005 at 7:51, T Petersen wrote: Almost. Catagories aren't stacked - I would like to see that x has 2 instances of 1 while y has 1 instance of 1. What's more, there are now TWO distinct barplots - the left one shows x, while the right one shows y. I could live with that, but what I'd ideally want is to have x and y beside each other for EACH catagory - so for catagory 1 you could see taht there are more x's than y's (two x's versus one y). But thanks for the help Mulholland, Tom wrote: barplot(matrix(c(x,y),ncol = 2),beside=T) Does this help ?barplot notes height: either a vector or matrix of values describing the bars which make up the plot. If 'height' is a vector, the plot consists of a sequence of rectangular bars with heights given by the values in the vector. If 'height' is a matrix and 'beside' is 'FALSE' then each bar of the plot corresponds to a column of 'height', with the values in the column giving the heights of stacked sub-bars making up the bar. If 'height' is a matrix and 'beside' is 'TRUE', then the values in each column are juxtaposed rather than stacked. -Original Message- From: T Petersen [mailto:[EMAIL PROTECTED] Sent: Friday, 18 February 2005 1:35 PM To: Kevin Wang Cc: r-help@stat.math.ethz.ch Subject: Re: [R] Barplot - Can't figure it out Ups, it should of course be barplot() in my mail, not boxplot:-) Kevin Wang wrote: Hi, T Petersen wrote: Hi, I have two catagorical vectors like this; x = c(1, 2, 4, 2, 1) y = c(2, 4, 2 ,4, 1) I want to set up a barplot with the catagories 1-4 horizontally and number of occurances vertically for each vector x,y. I've tried boxplot(table(x,y), beside=T) and boxplot(c(x,y), beside=T) Have you tried barplot(), instead of boxplot()??? Cheers, Kev __ 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 __ 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 __ 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 Petr Pikal [EMAIL PROTECTED] __ 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
Re: [R] Barplot - Can't figure it out
Wow, I'm getting confused...The syntax Petr suggested does what I wanted, but things are stille wrong...Maybe a bug? Let me explain. I got two vectors: x = c(3, 3, 3, 4, 3, 4, 3, 4, 3, 4) y = c(5, 2, 5, 5, 2, 2, 5, 5, 4, 2) then I do the barplot you suggest barplot(rbind(table(x), table(y)), beside=T) but things are wrong(there is no bar for catagory 3) and I get an error message: Warning message: number of columns of result not a multiple of vector length (arg 1) in: rbind(table(Quest1), table(Quest2)) Any ideas? Petr Pikal wrote: Hi If I understand correctly barplot(rbind(table(x), table(y)), beside=T) does what you want. Cheers Petr On 18 Feb 2005 at 7:51, T Petersen wrote: Almost. Catagories aren't stacked - I would like to see that x has 2 instances of 1 while y has 1 instance of 1. What's more, there are now TWO distinct barplots - the left one shows x, while the right one shows y. I could live with that, but what I'd ideally want is to have x and y beside each other for EACH catagory - so for catagory 1 you could see taht there are more x's than y's (two x's versus one y). But thanks for the help Mulholland, Tom wrote: barplot(matrix(c(x,y),ncol = 2),beside=T) Does this help ?barplot notes height: either a vector or matrix of values describing the bars which make up the plot. If 'height' is a vector, the plot consists of a sequence of rectangular bars with heights given by the values in the vector. If 'height' is a matrix and 'beside' is 'FALSE' then each bar of the plot corresponds to a column of 'height', with the values in the column giving the heights of stacked sub-bars making up the bar. If 'height' is a matrix and 'beside' is 'TRUE', then the values in each column are juxtaposed rather than stacked. -Original Message- From: T Petersen [mailto:[EMAIL PROTECTED] Sent: Friday, 18 February 2005 1:35 PM To: Kevin Wang Cc: r-help@stat.math.ethz.ch Subject: Re: [R] Barplot - Can't figure it out Ups, it should of course be barplot() in my mail, not boxplot:-) Kevin Wang wrote: Hi, T Petersen wrote: Hi, I have two catagorical vectors like this; x = c(1, 2, 4, 2, 1) y = c(2, 4, 2 ,4, 1) I want to set up a barplot with the catagories 1-4 horizontally and number of occurances vertically for each vector x,y. I've tried boxplot(table(x,y), beside=T) and boxplot(c(x,y), beside=T) Have you tried barplot(), instead of boxplot()??? Cheers, Kev __ 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 __ 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 __ 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 Petr Pikal [EMAIL PROTECTED] __ 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 __ 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
Re: [R] Barplot - Can't figure it out
On Fri, 18 Feb 2005 13:00:40 +0100 T Petersen wrote: Wow, I'm getting confused...The syntax Petr suggested does what I wanted, but things are stille wrong...Maybe a bug? Let me explain. I got two vectors: x = c(3, 3, 3, 4, 3, 4, 3, 4, 3, 4) y = c(5, 2, 5, 5, 2, 2, 5, 5, 4, 2) then I do the barplot you suggest barplot(rbind(table(x), table(y)), beside=T) but things are wrong(there is no bar for catagory 3) and I get an error message: Warning message: number of columns of result not a multiple of vector length (arg 1) in: rbind(table(Quest1), table(Quest2)) Any ideas? If x and y are categorical variables, you should tell R so (i.e., convert to a factor) and if both should have the same categories (i.e., levels) you can supply this information as well: R x - factor(x, levels = 2:5) R y - factor(y, levels = 2:5) Then, table() knows which categories to use: R rbind(x = table(x), y = table(y)) 2 3 4 5 x 0 6 4 0 y 4 0 1 5 and also the barplot() call given above will do the right thing. Z Petr Pikal wrote: Hi If I understand correctly barplot(rbind(table(x), table(y)), beside=T) does what you want. Cheers Petr On 18 Feb 2005 at 7:51, T Petersen wrote: Almost. Catagories aren't stacked - I would like to see that x has 2 instances of 1 while y has 1 instance of 1. What's more, there arenow TWO distinct barplots - the left one shows x, while the right oneshows y. I could live with that, but what I'd ideally want is to havex and y beside each other for EACH catagory - so for catagory 1 youcould see taht there are more x's than y's (two x's versus one y). Butthanks for the help Mulholland, Tom wrote: barplot(matrix(c(x,y),ncol = 2),beside=T) Does this help ?barplot notes height: either a vector or matrix of values describing the bars which make up the plot. If 'height' is a vector, the plot consists of a sequence of rectangular bars with heights given by the values in the vector. If 'height' is a matrix and 'beside' is 'FALSE' then each bar of the plot corresponds to a column of 'height', with the values in the column giving the heights of stacked sub-bars making up the bar. If 'height' is a matrix and 'beside' is 'TRUE', then the values in each column are juxtaposed rather than stacked. -Original Message- From: T Petersen [mailto:[EMAIL PROTECTED] Sent: Friday, 18 February 2005 1:35 PM To: Kevin Wang Cc: r-help@stat.math.ethz.ch Subject: Re: [R] Barplot - Can't figure it out Ups, it should of course be barplot() in my mail, not boxplot:-) Kevin Wang wrote: Hi, T Petersen wrote: Hi, I have two catagorical vectors like this; x = c(1, 2, 4, 2, 1) y = c(2, 4, 2 ,4, 1) I want to set up a barplot with the catagories 1-4 horizontally and number of occurances vertically for each vector x,y. I've tried boxplot(table(x,y), beside=T) and boxplot(c(x,y), beside=T) Have you tried barplot(), instead of boxplot()??? Cheers, Kev __ 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 __ 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 __ 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 Petr Pikal [EMAIL PROTECTED] __ 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 __ 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 __ 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
RE: [R] Barplot - Can't figure it out
What you want is probably: cxy - c(x,y) xy - rep( c(x,y), c(length(x),length(y)) ) ( txy - table(xy, cxy ) ) cxy xy 2 3 4 5 x 0 6 4 0 y 4 0 1 5 barplot( txy, beside=T ) Bendix Carstensen -- Bendix Carstensen Senior Statistician Steno Diabetes Center Niels Steensens Vej 2 DK-2820 Gentofte Denmark tel: +45 44 43 87 38 mob: +45 30 75 87 38 fax: +45 44 43 07 06 [EMAIL PROTECTED] www.biostat.ku.dk/~bxc -- -Original Message- From: [EMAIL PROTECTED] [mailto:[EMAIL PROTECTED] On Behalf Of T Petersen Sent: Friday, February 18, 2005 1:01 PM To: Petr Pikal Cc: r-help@stat.math.ethz.ch Subject: Re: [R] Barplot - Can't figure it out Wow, I'm getting confused...The syntax Petr suggested does what I wanted, but things are stille wrong...Maybe a bug? Let me explain. I got two vectors: x = c(3, 3, 3, 4, 3, 4, 3, 4, 3, 4) y = c(5, 2, 5, 5, 2, 2, 5, 5, 4, 2) then I do the barplot you suggest barplot(rbind(table(x), table(y)), beside=T) but things are wrong(there is no bar for catagory 3) and I get an error message: Warning message: number of columns of result not a multiple of vector length (arg 1) in: rbind(table(Quest1), table(Quest2)) Any ideas? __ 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
Re: [R] Barplot - Can't figure it out
On 18 Feb 2005 at 13:00, T Petersen wrote: Wow, I'm getting confused...The syntax Petr suggested does what I wanted, but things are stille wrong...Maybe a bug? Let me explain. Bugs are exceptionally rare in R. I got two vectors: x = c(3, 3, 3, 4, 3, 4, 3, 4, 3, 4) y = c(5, 2, 5, 5, 2, 2, 5, 5, 4, 2) then I do the barplot you suggest barplot(rbind(table(x), table(y)), beside=T) So you do not have same categories in both vectors. The only thing I can come up with is to fill some dummy vector, like xx-rep(NA,5) with xx[1:5 %in% as.numeric(names(table(x)))]-table(x) to keep both vectors same length and with NA in place where there is no category. Than simply rbinding both vectors and making barplot. but things are wrong(there is no bar for catagory 3) and I get an error message: Warning message: number of columns of result not a multiple of vector length (arg 1) in: rbind(table(Quest1), table(Quest2)) warning message says exactly what it says table(Quest1) and table(Quest2) does not result in the same categories, so rbinding vectors with different lengths is performed, shorter vector is recycled and warning is issued. Cheers Petr Any ideas? Petr Pikal wrote: Hi If I understand correctly barplot(rbind(table(x), table(y)), beside=T) does what you want. Cheers Petr On 18 Feb 2005 at 7:51, T Petersen wrote: Almost. Catagories aren't stacked - I would like to see that x has 2 instances of 1 while y has 1 instance of 1. What's more, there are now TWO distinct barplots - the left one shows x, while the right one shows y. I could live with that, but what I'd ideally want is to have x and y beside each other for EACH catagory - so for catagory 1 you could see taht there are more x's than y's (two x's versus one y). But thanks for the help Mulholland, Tom wrote: barplot(matrix(c(x,y),ncol = 2),beside=T) Does this help ?barplot notes height: either a vector or matrix of values describing the bars which make up the plot. If 'height' is a vector, the plot consists of a sequence of rectangular bars with heights given by the values in the vector. If 'height' is a matrix and 'beside' is 'FALSE' then each bar of the plot corresponds to a column of 'height', with the values in the column giving the heights of stacked sub-bars making up the bar. If 'height' is a matrix and 'beside' is 'TRUE', then the values in each column are juxtaposed rather than stacked. -Original Message- From: T Petersen [mailto:[EMAIL PROTECTED] Sent: Friday, 18 February 2005 1:35 PM To: Kevin Wang Cc: r-help@stat.math.ethz.ch Subject: Re: [R] Barplot - Can't figure it out Ups, it should of course be barplot() in my mail, not boxplot:-) Kevin Wang wrote: Hi, T Petersen wrote: Hi, I have two catagorical vectors like this; x = c(1, 2, 4, 2, 1) y = c(2, 4, 2 ,4, 1) I want to set up a barplot with the catagories 1-4 horizontally and number of occurances vertically for each vector x,y. I've tried boxplot(table(x,y), beside=T) and boxplot(c(x,y), beside=T) Have you tried barplot(), instead of boxplot()??? Cheers, Kev __ 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 __ 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 __ 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 Petr Pikal [EMAIL PROTECTED] __ 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 __ 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 Petr Pikal [EMAIL PROTECTED] __ 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
Re: [R] Barplot - Can't figure it out
Yeah, that's it. I have to catagorize the data AND tell R how many catagories there are. It works perfectly now and I've learned some more:-D Great. Achim Zeileis wrote: On Fri, 18 Feb 2005 13:00:40 +0100 T Petersen wrote: Wow, I'm getting confused...The syntax Petr suggested does what I wanted, but things are stille wrong...Maybe a bug? Let me explain. I got two vectors: x = c(3, 3, 3, 4, 3, 4, 3, 4, 3, 4) y = c(5, 2, 5, 5, 2, 2, 5, 5, 4, 2) then I do the barplot you suggest barplot(rbind(table(x), table(y)), beside=T) but things are wrong(there is no bar for catagory 3) and I get an error message: Warning message: number of columns of result not a multiple of vector length (arg 1) in: rbind(table(Quest1), table(Quest2)) Any ideas? If x and y are categorical variables, you should tell R so (i.e., convert to a factor) and if both should have the same categories (i.e., levels) you can supply this information as well: R x - factor(x, levels = 2:5) R y - factor(y, levels = 2:5) Then, table() knows which categories to use: R rbind(x = table(x), y = table(y)) 2 3 4 5 x 0 6 4 0 y 4 0 1 5 and also the barplot() call given above will do the right thing. Z Petr Pikal wrote: Hi If I understand correctly barplot(rbind(table(x), table(y)), beside=T) does what you want. Cheers Petr On 18 Feb 2005 at 7:51, T Petersen wrote: Almost. Catagories aren't stacked - I would like to see that x has 2 instances of 1 while y has 1 instance of 1. What's more, there arenow TWO distinct barplots - the left one shows x, while the right oneshows y. I could live with that, but what I'd ideally want is to havex and y beside each other for EACH catagory - so for catagory 1 youcould see taht there are more x's than y's (two x's versus one y). Butthanks for the help Mulholland, Tom wrote: barplot(matrix(c(x,y),ncol = 2),beside=T) Does this help ?barplot notes height: either a vector or matrix of values describing the bars which make up the plot. If 'height' is a vector, the plot consists of a sequence of rectangular bars with heights given by the values in the vector. If 'height' is a matrix and 'beside' is 'FALSE' then each bar of the plot corresponds to a column of 'height', with the values in the column giving the heights of stacked sub-bars making up the bar. If 'height' is a matrix and 'beside' is 'TRUE', then the values in each column are juxtaposed rather than stacked. -Original Message- From: T Petersen [mailto:[EMAIL PROTECTED] Sent: Friday, 18 February 2005 1:35 PM To: Kevin Wang Cc: r-help@stat.math.ethz.ch Subject: Re: [R] Barplot - Can't figure it out Ups, it should of course be barplot() in my mail, not boxplot:-) Kevin Wang wrote: Hi, T Petersen wrote: Hi, I have two catagorical vectors like this; x = c(1, 2, 4, 2, 1) y = c(2, 4, 2 ,4, 1) I want to set up a barplot with the catagories 1-4 horizontally and number of occurances vertically for each vector x,y. I've tried boxplot(table(x,y), beside=T) and boxplot(c(x,y), beside=T) Have you tried barplot(), instead of boxplot()??? Cheers, Kev __ 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 __ 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 __ 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 Petr Pikal [EMAIL PROTECTED] __ 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 __ 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 __ 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 __ 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
Re: [R] barplot and ylim - display problems
On Fri, 2005-02-18 at 14:47 +, Dan Bolser wrote: The following single line of code shows what I am trying to do, and the problem I am having... barplot(c(101,102,103),ylim=c(100,103)) The 'xaxis' is missing, and the grey bars 'fall off' the plot area. This is generally ugly, and I would like to trim the bars (ideally they would have a ragged appearance to show that I am 'zooming in'). I can see why what I am trying to do is conceptually a bit tricky, as the yaxis needs to be closly inspected to see the data in its propper context. This is simply fixed by showing... barplot(c(101,102,103)) However, I want to first show the data in its propper context, then 'zoom in' to highlight the difference between the bars. I tried covering up the bottom of the chart with a rect() command, but it wont draw ouside the area highlighted with the box command, for example barplot(c(101,102,103),ylim=c(100,103)) box() rect(0.7,0,1.9,102.5,col=white) So I can't work out how to stop bars falling off the end of the plot, so my labels are being written on the bars. How can I fix this? Dan, Try this: barplot(c(101,102,103),ylim=c(100,103), xpd = FALSE) Note that the setting of par(xpd) clips the bars outside the plot region. See ?par for more information. HTH, Marc Schwartz __ 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
Re: [R] barplot and ylim - display problems
Dan Bolser wrote: The following single line of code shows what I am trying to do, and the problem I am having... barplot(c(101,102,103),ylim=c(100,103)) The 'xaxis' is missing, and the grey bars 'fall off' the plot area. This is generally ugly, and I would like to trim the bars (ideally they would have a ragged appearance to show that I am 'zooming in'). I can see why what I am trying to do is conceptually a bit tricky, as the yaxis needs to be closly inspected to see the data in its propper context. This is simply fixed by showing... barplot(c(101,102,103)) So you want to turn clipping on using xpd=FALSE, e.g. something like bp - barplot(c(101,102,103), ylim=c(100,103), xpd=FALSE) axis(1, at=bp, labels=1:3) Uwe Ligges However, I want to first show the data in its propper context, then 'zoom in' to highlight the difference between the bars. I tried covering up the bottom of the chart with a rect() command, but it wont draw ouside the area highlighted with the box command, for example barplot(c(101,102,103),ylim=c(100,103)) box() rect(0.7,0,1.9,102.5,col=white) So I can't work out how to stop bars falling off the end of the plot, so my labels are being written on the bars. How can I fix this? __ 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 __ 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
Re: [R] barplot and ylim - display problems
I think a workaround, that will do what you want is: barplot(c(101,102,103) - 100, offset = 100) hth, Z On Fri, 18 Feb 2005 14:47:24 + (GMT) Dan Bolser wrote: The following single line of code shows what I am trying to do, and the problem I am having... barplot(c(101,102,103),ylim=c(100,103)) The 'xaxis' is missing, and the grey bars 'fall off' the plot area. This is generally ugly, and I would like to trim the bars (ideally they would have a ragged appearance to show that I am 'zooming in'). I can see why what I am trying to do is conceptually a bit tricky, as the yaxis needs to be closly inspected to see the data in its propper context. This is simply fixed by showing... barplot(c(101,102,103)) However, I want to first show the data in its propper context, then 'zoom in' to highlight the difference between the bars. I tried covering up the bottom of the chart with a rect() command, but it wont draw ouside the area highlighted with the box command, for example barplot(c(101,102,103),ylim=c(100,103)) box() rect(0.7,0,1.9,102.5,col=white) So I can't work out how to stop bars falling off the end of the plot, so my labels are being written on the bars. How can I fix this? __ 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 __ 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
Re: [R] Barplot - Can't figure it out
Here is a generalisation of the function that others have suggested to take take more than 2 vectors. my.barplot - function(...){ my.list - list(...) lev - sort( unique( unlist(my.list) ) ) tmp - t(sapply( my.list, function(v) table(factor(v, levels=lev))) ) barplot(tmp, beside=T) } w - c(3, 3, 3, 4, 3, 4, 3, 4, 3, 4) x - c(5, 2, 5, 5, 2, 2, 5, 5, 4, 2) y - c(1, 2, 3, 0, 5, 0, 1, 2, 1, 2) z - sample( c(w,x,y,z), 50, replace=TRUE ) my.barplot( w, x, y, z ) Regards, Adai On Fri, 2005-02-18 at 14:00 +0100, T Petersen wrote: Yeah, that's it. I have to catagorize the data AND tell R how many catagories there are. It works perfectly now and I've learned some more:-D Great. Achim Zeileis wrote: On Fri, 18 Feb 2005 13:00:40 +0100 T Petersen wrote: Wow, I'm getting confused...The syntax Petr suggested does what I wanted, but things are stille wrong...Maybe a bug? Let me explain. I got two vectors: x = c(3, 3, 3, 4, 3, 4, 3, 4, 3, 4) y = c(5, 2, 5, 5, 2, 2, 5, 5, 4, 2) then I do the barplot you suggest barplot(rbind(table(x), table(y)), beside=T) but things are wrong(there is no bar for catagory 3) and I get an error message: Warning message: number of columns of result not a multiple of vector length (arg 1) in: rbind(table(Quest1), table(Quest2)) Any ideas? If x and y are categorical variables, you should tell R so (i.e., convert to a factor) and if both should have the same categories (i.e., levels) you can supply this information as well: R x - factor(x, levels = 2:5) R y - factor(y, levels = 2:5) Then, table() knows which categories to use: R rbind(x = table(x), y = table(y)) 2 3 4 5 x 0 6 4 0 y 4 0 1 5 and also the barplot() call given above will do the right thing. Z Petr Pikal wrote: Hi If I understand correctly barplot(rbind(table(x), table(y)), beside=T) does what you want. Cheers Petr On 18 Feb 2005 at 7:51, T Petersen wrote: Almost. Catagories aren't stacked - I would like to see that x has 2 instances of 1 while y has 1 instance of 1. What's more, there arenow TWO distinct barplots - the left one shows x, while the right oneshows y. I could live with that, but what I'd ideally want is to havex and y beside each other for EACH catagory - so for catagory 1 youcould see taht there are more x's than y's (two x's versus one y). Butthanks for the help Mulholland, Tom wrote: barplot(matrix(c(x,y),ncol = 2),beside=T) Does this help ?barplot notes height: either a vector or matrix of values describing the bars which make up the plot. If 'height' is a vector, the plot consists of a sequence of rectangular bars with heights given by the values in the vector. If 'height' is a matrix and 'beside' is 'FALSE' then each bar of the plot corresponds to a column of 'height', with the values in the column giving the heights of stacked sub-bars making up the bar. If 'height' is a matrix and 'beside' is 'TRUE', then the values in each column are juxtaposed rather than stacked. -Original Message- From: T Petersen [mailto:[EMAIL PROTECTED] Sent: Friday, 18 February 2005 1:35 PM To: Kevin Wang Cc: r-help@stat.math.ethz.ch Subject: Re: [R] Barplot - Can't figure it out Ups, it should of course be barplot() in my mail, not boxplot:-) Kevin Wang wrote: Hi, T Petersen wrote: Hi, I have two catagorical vectors like this; x = c(1, 2, 4, 2, 1) y = c(2, 4, 2 ,4, 1) I want to set up a barplot with the catagories 1-4 horizontally and number of occurances vertically for each vector x,y. I've tried boxplot(table(x,y), beside=T) and boxplot(c(x,y), beside=T) Have you tried barplot(), instead of boxplot()??? Cheers, Kev __ 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 __ 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 __ 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 Petr
Re: [R] Barplot - Can't figure it out
Hi, T Petersen wrote: Hi, I have two catagorical vectors like this; x = c(1, 2, 4, 2, 1) y = c(2, 4, 2 ,4, 1) I want to set up a barplot with the catagories 1-4 horizontally and number of occurances vertically for each vector x,y. I've tried boxplot(table(x,y), beside=T) and boxplot(c(x,y), beside=T) Have you tried barplot(), instead of boxplot()??? Cheers, Kev -- Ko-Kang Kevin Wang PhD Student Centre for Mathematics and its Applications Building 27, Room 1004 Mathematical Sciences Institute (MSI) Australian National University Canberra, ACT 0200 Australia Homepage: http://wwwmaths.anu.edu.au/~wangk/ Ph (W): +61-2-6125-2431 Ph (H): +61-2-6125-7407 Ph (M): +61-40-451-8301 __ 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
Re: [R] Barplot - Can't figure it out
Ups, it should of course be barplot() in my mail, not boxplot:-) Kevin Wang wrote: Hi, T Petersen wrote: Hi, I have two catagorical vectors like this; x = c(1, 2, 4, 2, 1) y = c(2, 4, 2 ,4, 1) I want to set up a barplot with the catagories 1-4 horizontally and number of occurances vertically for each vector x,y. I've tried boxplot(table(x,y), beside=T) and boxplot(c(x,y), beside=T) Have you tried barplot(), instead of boxplot()??? Cheers, Kev __ 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
RE: [R] Barplot - Can't figure it out
barplot(matrix(c(x,y),ncol = 2),beside=T) Does this help ?barplot notes height: either a vector or matrix of values describing the bars which make up the plot. If 'height' is a vector, the plot consists of a sequence of rectangular bars with heights given by the values in the vector. If 'height' is a matrix and 'beside' is 'FALSE' then each bar of the plot corresponds to a column of 'height', with the values in the column giving the heights of stacked sub-bars making up the bar. If 'height' is a matrix and 'beside' is 'TRUE', then the values in each column are juxtaposed rather than stacked. -Original Message- From: T Petersen [mailto:[EMAIL PROTECTED] Sent: Friday, 18 February 2005 1:35 PM To: Kevin Wang Cc: r-help@stat.math.ethz.ch Subject: Re: [R] Barplot - Can't figure it out Ups, it should of course be barplot() in my mail, not boxplot:-) Kevin Wang wrote: Hi, T Petersen wrote: Hi, I have two catagorical vectors like this; x = c(1, 2, 4, 2, 1) y = c(2, 4, 2 ,4, 1) I want to set up a barplot with the catagories 1-4 horizontally and number of occurances vertically for each vector x,y. I've tried boxplot(table(x,y), beside=T) and boxplot(c(x,y), beside=T) Have you tried barplot(), instead of boxplot()??? Cheers, Kev __ 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 __ 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
Re: [R] Barplot - Can't figure it out
Almost. Catagories aren't stacked - I would like to see that x has 2 instances of 1 while y has 1 instance of 1. What's more, there are now TWO distinct barplots - the left one shows x, while the right one shows y. I could live with that, but what I'd ideally want is to have x and y beside each other for EACH catagory - so for catagory 1 you could see taht there are more x's than y's (two x's versus one y). But thanks for the help Mulholland, Tom wrote: barplot(matrix(c(x,y),ncol = 2),beside=T) Does this help ?barplot notes height: either a vector or matrix of values describing the bars which make up the plot. If 'height' is a vector, the plot consists of a sequence of rectangular bars with heights given by the values in the vector. If 'height' is a matrix and 'beside' is 'FALSE' then each bar of the plot corresponds to a column of 'height', with the values in the column giving the heights of stacked sub-bars making up the bar. If 'height' is a matrix and 'beside' is 'TRUE', then the values in each column are juxtaposed rather than stacked. -Original Message- From: T Petersen [mailto:[EMAIL PROTECTED] Sent: Friday, 18 February 2005 1:35 PM To: Kevin Wang Cc: r-help@stat.math.ethz.ch Subject: Re: [R] Barplot - Can't figure it out Ups, it should of course be barplot() in my mail, not boxplot:-) Kevin Wang wrote: Hi, T Petersen wrote: Hi, I have two catagorical vectors like this; x = c(1, 2, 4, 2, 1) y = c(2, 4, 2 ,4, 1) I want to set up a barplot with the catagories 1-4 horizontally and number of occurances vertically for each vector x,y. I've tried boxplot(table(x,y), beside=T) and boxplot(c(x,y), beside=T) Have you tried barplot(), instead of boxplot()??? Cheers, Kev __ 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 __ 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 __ 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
Re: [R] Barplot at the axes of another plot
On Thu, 2005-01-20 at 23:53 +0100, Robin Gruna wrote: Hi, I want to draw a barplot at the axes of another plot. I saw that with two histogramms and a scatterplot in a R graphics tutorial somewhere on the net, seemed to be a 2d histogramm. Can someone figure out what I mean and give me a hint to create such a graphic? Thank you very much, Robin See the examples in ?layout, which has the scatterplot with the marginal histograms. HTH, Marc Schwartz __ 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
Re: [R] barplot() options for intervals on axes
Sebastien Moretti wrote: Hello, I am a beginner with R. I read many tutorials and the FAQ but I cannot solve my problem. I use barplot() to view my graph. I try to get more interval marks on y axis. I wasn't able to find options in 'help(barplot)' or 'help(par)' to do this with barplot(). See ?par and ?axis. You might want to omit the y-axis completely at first (argument yaxt=n) and add one manually useing axis(2, ). I seek for another option to print y values on my bars like on the graph of the R homepage: http://www.r-project.org/ Click on the image and see the code how it was generated. Uwe Ligges Thanks for your help. __ [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
Re: [R] barplot() options for intervals on axes
Did you see the lab argument to par()? 'lab' A numerical vector of the form 'c(x, y, len)' which modifies the way that axes are annotated. The values of 'x' and 'y' give the (approximate) number of tickmarks on the x and y axes and 'len' specifies the label size. The default is 'c(5, 5, 7)'. _Currently_, 'len' _is unimplemented_. You might want something like this: par(lab=c(5,10,7)) barplot(runif(10)) Sebastien Moretti wrote: Hello, I am a beginner with R. I read many tutorials and the FAQ but I cannot solve my problem. I use barplot() to view my graph. I try to get more interval marks on y axis. I wasn't able to find options in 'help(barplot)' or 'help(par)' to do this with barplot(). I seek for another option to print y values on my bars like on the graph of the R homepage: http://www.r-project.org/ Thanks for your help. -- Chuck Cleland, Ph.D. NDRI, Inc. 71 West 23rd Street, 8th floor New York, NY 10010 tel: (212) 845-4495 (Tu, Th) tel: (732) 452-1424 (M, W, F) fax: (917) 438-0894 __ [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
Re: [R] barplot() options for intervals on axes
Did you see the lab argument to par()? 'lab' A numerical vector of the form 'c(x, y, len)' which modifies the way that axes are annotated. The values of 'x' and 'y' give the (approximate) number of tickmarks on the x and y axes and 'len' specifies the label size. The default is 'c(5, 5, 7)'. _Currently_, 'len' _is unimplemented_. You might want something like this: par(lab=c(5,10,7)) barplot(runif(10)) 'lab' doesn't change my graph. It is always the same. Maybe it doesn't work with other options I use in barplot: barplot(y,xlab=Number of splice variants,ylab=Number of genes,col=red1,names.arg=x,border=red1,axes=TRUE,ylim=c(0,max(y))) Hello, I am a beginner with R. I read many tutorials and the FAQ but I cannot solve my problem. I use barplot() to view my graph. I try to get more interval marks on y axis. I wasn't able to find options in 'help(barplot)' or 'help(par)' to do this with barplot(). I seek for another option to print y values on my bars like on the graph of the R homepage: http://www.r-project.org/ Thanks for your help. -- Sebastien MORETTI Linux User - #327894 CNRS - IGS 31 chemin Joseph Aiguier 13402 Marseille cedex 20, FRANCE tel. +33 (0)4 91 16 44 55 __ [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
Re: [R] barplot() options for intervals on axes
On Mon, 2004-12-06 at 15:30 +0100, Sebastien Moretti wrote: Hello, I am a beginner with R. I read many tutorials and the FAQ but I cannot solve my problem. I use barplot() to view my graph. I try to get more interval marks on y axis. I wasn't able to find options in 'help(barplot)' or 'help(par)' to do this with barplot(). I seek for another option to print y values on my bars like on the graph of the R homepage: http://www.r-project.org/ Thanks for your help. The general process of customizing the annotation of the axes for a variety of plots is posted frequently to this e-mail list, so a search of the archive using axis as the keyword yields almost 2,000 hits. Using axis labels narrows that to 650, which are more relevant. The key is to inhibit the generation of the default y axis by using the argument 'yaxt = n': Compare: barplot(1:5) versus barplot(1:5, yaxt = n) You can then use the axis() function to customize the y axis values: barplot(1:5, yaxt = n) axis(2, at = seq(0, 5, 0.25), las = 1) help(par) provides additional information on the graphic parameters, which are the key to these types of customizations. See ?axis for more information on that function as well. To your second query, the key is to note that barplot() returns the bar midpoints, which is referenced in the Value section of ?barplot. Thus: mp - barplot(1:5, yaxt = n, ylim = c(0, 6)) axis(2, at = seq(0, 5, 0.25), las = 1) text(mp, 1:5, labels = 1:5, pos = 3) See ?text for more information. Also, note that I increased the range of the y axis here to make room for the bar text labels (primarily the final tallest bar). Finally, there is an article in the R Help Desk section of the October 2003 R News on basic graphic operations in R, which you might find helpful. A direct link to it is: http://cran.r-project.org/doc/Rnews/Rnews_2003-2.pdf HTH, Marc Schwartz __ [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
Re: [R] barplot() options for intervals on axes
Hello, I am a beginner with R. I read many tutorials and the FAQ but I cannot solve my problem. I use barplot() to view my graph. I try to get more interval marks on y axis. I wasn't able to find options in 'help(barplot)' or 'help(par)' to do this with barplot(). I seek for another option to print y values on my bars like on the graph of the R homepage: http://www.r-project.org/ Thanks for your help. The general process of customizing the annotation of the axes for a variety of plots is posted frequently to this e-mail list, so a search of the archive using axis as the keyword yields almost 2,000 hits. Using axis labels narrows that to 650, which are more relevant. The key is to inhibit the generation of the default y axis by using the argument 'yaxt = n': Compare: barplot(1:5) versus barplot(1:5, yaxt = n) You can then use the axis() function to customize the y axis values: barplot(1:5, yaxt = n) axis(2, at = seq(0, 5, 0.25), las = 1) It's exactly what I seek for ! There are too many answers in the FAQ. So, I use axis(2,at=c(0,round(max(y)/8),round(max(y)/4),round(max(y)/2),round(3*max(y)/4),max(y))) to print the vertical axe I want. help(par) provides additional information on the graphic parameters, which are the key to these types of customizations. See ?axis for more information on that function as well. To your second query, the key is to note that barplot() returns the bar midpoints, which is referenced in the Value section of ?barplot. Thus: mp - barplot(1:5, yaxt = n, ylim = c(0, 6)) axis(2, at = seq(0, 5, 0.25), las = 1) text(mp, 1:5, labels = 1:5, pos = 3) The text() command prints y value labels over my bars Maybe some examples like that should be in the R manual Thanks See ?text for more information. Also, note that I increased the range of the y axis here to make room for the bar text labels (primarily the final tallest bar). Finally, there is an article in the R Help Desk section of the October 2003 R News on basic graphic operations in R, which you might find helpful. A direct link to it is: http://cran.r-project.org/doc/Rnews/Rnews_2003-2.pdf HTH, Marc Schwartz -- Sebastien MORETTI Linux User - #327894 CNRS - IGS 31 chemin Joseph Aiguier 13402 Marseille cedex 20, FRANCE tel. +33 (0)4 91 16 44 55 __ [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
Re: [R] barplot() options for intervals on axes
On Mon, 2004-12-06 at 16:31 +0100, Sebastien Moretti wrote: There are too many answers in the FAQ. Given the discussions here of late, I suspect that there will be one or two folks who might disagree with that statement... ;-) Marc __ [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
Fwd: Re: [R] barplot() options for intervals on axes
There are too many answers in the FAQ. For this topic ! Marc Schwartz -- Sebastien MORETTI Linux User - #327894 CNRS - IGS 31 chemin Joseph Aiguier 13402 Marseille cedex 20, FRANCE tel. +33 (0)4 91 16 44 55 __ [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
Re: [R] barplot() using beside=TRUE and the density argument
__ [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
Re: [R] barplot() using beside=TRUE and the density argument
On Wed, 2004-12-01 at 10:46 +, michael watson (IAH-C) wrote: Hi I am using barplot() to draw some barplots, with a matrix as the data so that multiple bars are drawn for each data point. I want to use the argument beside=TRUE to juxtapose the bars instead of stacking them. If I execute: barplot(data,names.arg=names,density=c(20,10),beside=FALSE) I get the expected behaviour i.e. the bottom part of the column is shaded 20 lines per inch, the top part 10 lines per inch. However, if I try: barplot(data,names.arg=names,density=c(20,10),beside=TRUE) I don't get what *I* would expect (which admittedly might be the wrong thing!). What happens is that the left bar for each data point is shaded 20 lines per inch, and the right bar is not shaded at all. Any help would be very much appreciated. Mick Without a reproducible example, it is hard to know exactly what you are seeing. Running the following example: barplot(matrix(1:12, ncol = 6), density = c(20, 10), beside = TRUE) I will admit that the right hand bars in the plot have a shading that is very light and may be difficult to see on your system, but they are there. You might want to try the following: barplot(matrix(1:12, ncol = 6), density = c(20, 10), col = c(red, blue), beside = TRUE) to see if the addition of color makes a difference, or if not, try to increase the second density value. If this does not help, please provide a reproducible example. HTH, Marc Schwartz __ [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
Re: [R] barplot(2?) with CI from a zero reference line
On Fri, 2004-11-26 at 07:56 +0100, Jean-Louis Abitbol wrote: Dear R Users, (and dear Marc) First of all many thanks for the answers to my previous questions. I would like to barplot the mean percent change of a variate with it's CI. Bars should start from the zero reference line to height (in barplot2). Is there a way to tweak barplot2, for example, to do that ? I have tried to see what the function was but unlike other functions was not able to list it by barplot2. Is it because it is called through UseMethods ? Thanks for any help. Jean-Louis Jean-Louis, I may be mis-understanding what you are trying to do here, but do you want to have a horizontal zero reference line in the middle of the plot, such that you can have positive change bars going up from the line and negative change bars going down from the line? If so, the default mechanism will work: barplot2(c(-1, 2, -3, 5, 4, -4)) abline(h = 0) If that is the correct basic plot, just adjust the values for the CI's accordingly. HTH, Marc Schwartz __ [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
RE: [R] barplot(2?) with CI from a zero reference line
I didn't know how to do this but I knew it had to been asked about. Try getS3method(barplot2,default) Make sure you've loaded gplots. I guessed default, but I wonder how you would find out the class if it had been something else. I guess that's something to work on when I'm next twiddling my thumbs. Tom Mulholland -Original Message- From: Jean-Louis Abitbol [mailto:[EMAIL PROTECTED] Sent: Friday, 26 November 2004 2:56 PM To: [EMAIL PROTECTED] Subject: [R] barplot(2?) with CI from a zero reference line Dear R Users, (and dear Marc) First of all many thanks for the answers to my previous questions. I would like to barplot the mean percent change of a variate with it's CI. Bars should start from the zero reference line to height (in barplot2). Is there a way to tweak barplot2, for example, to do that ? I have tried to see what the function was but unlike other functions was not able to list it by barplot2. Is it because it is called through UseMethods ? Thanks for any help. Jean-Louis __ [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 __ [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
Re: [R] Barplot difficulties
Heather J. Branton wrote: Hello. I am an R newbie struggling to learn and use R . I have read many portions of the R Reference Manual, as well as the FAQs. Given that I learn something new each time, I know I might be missing something obvious. But I appeal to your good nature to help me through this initial problem. I have attached a pdf file to demonstrate what I desire and have listed what my data looks like in Excel (below). Following is the data and script I developed - which does not provide what I want. Dear Heather - Please read Bill Cleveland's book The Elements of Graphing Data. A MUCH better plot can be produced. And let time be one of the first variables to vary. -- Frank E Harrell Jr Professor and Chair School of Medicine Department of Biostatistics Vanderbilt University __ [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
Re: [R] Barplot difficulties
On Mon, 2004-11-15 at 19:03 -0500, Heather J. Branton wrote: Hello. I am an R newbie struggling to learn and use R . I have read many portions of the R Reference Manual, as well as the FAQs. Given that I learn something new each time, I know I might be missing something obvious. But I appeal to your good nature to help me through this initial problem. I have attached a pdf file to demonstrate what I desire and have listed what my data looks like in Excel (below). Following is the data and script I developed - which does not provide what I want. My immediate goal is to create a barplot in R similar to the attached pdf chart. But I am stuck on several problems. First, I would like to have 2 labels below the barplot - one label for each bar and one for each group of bars. Second, I would like to vary color by group (instead of by bar). I assume that I need to do use some sort of syntax within the color option but have not yet figured it out. I have made two different plot attempts -- one resulting in the bars being grouped appropriately but missing the labels below the x-axis; the other giving me the individual labels but not grouped as I need. snip How about something like this: # Don't use 'sample' for the name here, as sample() is a function MyData - t(read.table(sample.dat, sep= , , header = TRUE)) # These may be closer to the PDF chart colors # You need to repeat them to color each group the same, rather # than alternating bar colors MyCols - rep(c(lightcyan,cornsilk,lavender), each = 10) # adjust the margins par(mar = c(7, 5, 6, 4)) # Now do the barplot: # Note barplot() returns the bar midpoints in 'mp' # use 'names.arg' for the individual bar names from MyData # set 'las = 2' for vertical labels # set 'ylim' to c(0, 20) for the y axis range # set 'yaxt = n' to not draw the y axis tick marks mp - barplot(MyData, beside = TRUE, col = MyCols, main = Rate by Group and Year, ylab = Rate, names.arg = rep(rownames(MyData), 3), las = 2, cex.names = 0.75, ylim = c(0,20), yaxt = n) # Now set up the y axis tick marks and labels ticks - seq(0, 20, 2) axis(2, at = ticks, las = 1, labels = formatC(ticks, format = f, digits = 1)) # Draw a box around the whole thing box() # Now draw the years. Note from ?barplot that colMeans(mp) are # the group midpoints mtext(side = 1, at = colMeans(mp), line = 3.5, text = colnames(MyData)) # Now draw the x axis label mtext(side = 1, line = 5.5, text = Test and Year) Hope that gets you what you need. You can adjust the font sizes, etc. as you require. Note that unlike Excel, the 0 (zero) columns are not dropped. :-) HTH, Marc Schwartz __ [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
Re: [R] barplot
Sepp Gurgel wrote: I have a table Do you mean a data.frame? with two columns, one with types of blood (A, B, AB or 0) and one with the factor (negative = -1 or positive = 1). And from these you made a table? my.table - table(my.data.frame) How can I combine those two columns so that 7 bars are plotted (A, B, AB, 0, -A, -B and -0)? Now you can say blood.id - outer(rownames(my.table), colnames(m.ytable), paste, sep=) barplot(as.vector(my.table), names = blood.id) Uwe Ligges -- __ [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 __ [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
Re: [R] barplot with vcd library
Tatsuki Koyama Tatsuki.Koyama at Vanderbilt.edu writes: : : 'barplot' doesn't seem to work with vcd library. : Am I supposed to detach vcd when I want to use barplot? : Here's an example. : Say I have the following matrix, : : m - matrix(c(1,2,3, 4,5,6, 3,4,5, 2,3,4), ncol=4) : m : [,1] [,2] [,3] [,4] : [1,]1432 : [2,]2543 : [3,]3654 : : Then : barplot(m) : gives a barplot of the data. : : However, when I attach 'vcd' library, the same command does not seem : to work. graphics::barplot(m) will tell R you want the version in graphics rather than the one in vcd. __ [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
Re: [R] barplot and names.arg
On Fri, 2004-08-13 at 09:22, Luis Rideau Cruz wrote: R-help Is there any option to get closer the x-axis and names.arg from barplot? Thank you Using mtext() you can do something like the following: data(VADeaths) # Now place labels closer to the x axis # set 'axisnames' to FALSE so the default # labels are not drawn. Also note that barplot() # returns the bar midpoints, so set 'mp' to the return # values mp - barplot(VADeaths, axisnames = FALSE) # Now use mtext() for the axis labels mtext(text = colnames(VADeaths), side = 1, at = mp, line = 0) # clean up rm(VADeaths) You can adjust the 'line = 0' argument to move the labels closer to and farther away from the axis. HTH, Marc Schwartz __ [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
Re: [R] barplot
Carlos Guevel wrote: I´ve tried version 1.9.0 barplot with these (and others) example from the help page: tN - table(Ni - rpois(100, lambda=5)) r - barplot(tN, col='gray') I get : ...OLE_Obj... Same example with version 1.8.1 gives the following result: ...OLE_Obj... What is wrong with v.1.9.0? Thanks, Carlos Guevel This has been reported a while back: http://r-bugs.biostat.ku.dk/cgi-bin/R/Graphics?id=6777;expression=barplot;user=guest which also suggests a workaround. tN - table(Ni - rpois(100, lambda=5)) r - barplot(as.vector(tN), col='gray') Alternatively, barplot2 in the gregmisc package should also work. library(gregmisc) tN - table(Ni - rpois(100, lambda=5)) r - barplot2(tN, col='gray') --sundar __ [EMAIL PROTECTED] mailing list https://www.stat.math.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html
Re: [R] barplot fill patterns
On Sun, Apr 18, 2004 at 11:28:09PM -0400, Hector L. Ayala-del-Rio wrote: Dear R-helpers, I will like to know if there is a way to generate a stacked column graph using both patterns and colors to fill the bars. I have many categories for the number of color available in R, so I will like R to start with solid colors and then use patterns an colors. I have been 1. Density patterns: see the help of barplot (?barplot), density gives the number of lines per inch, angle gives the shading angle. Both can be vectors, and will be recycled. 2. Look at the package RColorBrewer, a package with predefined palettes of three types, each with colors that are easy to distinguish visually. Combining the above two will give you a lot of variation. Experiment. they belong to different categories. How many different colors are available in R?? I know it is a silly question but I have looked R has a continous palette, so I would say it has 2^24 ~ 16 million colors on most devices. The question doesn't make sense, though: your eyes will only be able to distinguish a few shades in the spectrum. everywhere and I can not find it. I have also tried to add the legend, with the difficulty that overlaps with the plot. Does anybody know how to adjust the size of the graph and the legend so they can fit in the same page??? Below is how part of the data looks and the code I have experiment with commands like par(xpd=NA) par(mar=c(3.1,4.1,1.1,2.1)) which disable clipping and extend the margin. Use the legend() function after barplot, it lets you specify the coordinates. barplot(t(Control.cfo.norm.mat),beside=F,space=.3,legend.text=colnames( Control.cfo.norm.mat),col=(0:100),las=3, density=rep(c(85,55,-1),5),angle=rep(c(45,90,180),5)) Everything makes sense except col=(0:100). Use either color names (eg green) or hexadecimal colors (eg #00FF00), many functions can be used to generate the latter, eg heat.colors() and its friends, RColorBrewer, etc. Using rep(..., each=..., times=...) you can generate useful combinations of patterns/colors/angles. Best, Tamas -- Tamás K. Papp E-mail: [EMAIL PROTECTED] Please try to send only (latin-2) plain text, not HTML or other garbage. __ [EMAIL PROTECTED] mailing list https://www.stat.math.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html
Re: [R] Barplot errors in MASS script
[EMAIL PROTECTED] wrote: Reading Modern Applied Statististics with S and trying the corresponding examples both in the book and in ../lib/R/library/MASS/script, I'm now trying chapter 4 plotting bars with the following code on a linux box with R 1.8.1: -- library(MASS) library(lattice) options(echo=T, width=65, digits=5) lung.deaths - aggregate(ts.union(mdeaths, fdeaths), 1) barplot(t(lung.deaths), names = dimnames(lung.deaths)[[1]], main = UK deaths from lung disease) if(interactive()) legend(locator(1), c(Males, Females), fill = c(2, 3)) --- The legend doesn't look correct with respect to the picture at page 72 of the book for two reasons: 1) The legend has a transparent background while in the book is correctly opaque (and, above all, this is the background I expect!); Set the argument bg = white 2) One of the two variables is represented in the legend with a different colour from the same variable in the bars plot (green instead of yellow) Use heat.colors() (barplot() uses it to generate the colors). How could I set 1 and 2 right? legend(locator(1), c(Males, Females), fill = heat.colors(2), bg = white) That points us to a documentation bug in ?legend, whioch tells us in its Arguments section: bg the background color for the legend box. (Note that this is only used if bty = n.) Obviously, it is used if bty = o, but *not* if n. Uwe Ligges Thanks for your help Vittorio __ [EMAIL PROTECTED] mailing list https://www.stat.math.ethz.ch/mailman/listinfo/r-help __ [EMAIL PROTECTED] mailing list https://www.stat.math.ethz.ch/mailman/listinfo/r-help
Re: [R] barplot plot together
juli == juli g pausas [EMAIL PROTECTED] on Thu, 18 Dec 2003 10:54:08 +0100 writes: juli Dear colleges, juli I'm trying to combine a barplot and a plot in a single figure as follows: juli data - 1:6 juli t - barplot(data, axes=F) juli par(new= T) juli plot(t, data, type=b) juli However, as you can see in the example, the dots of juli the second plot do not fall in the midpoint of the juli bars in the first. Any trick for setting the 2 plots juli at the same scale? yes, use bd - barplot(data) points(bd, data, type = b) instead. A general recommendation: Try to *not* use par(new = TRUE) if you can. Martin __ [EMAIL PROTECTED] mailing list https://www.stat.math.ethz.ch/mailman/listinfo/r-help
Re: [R] barplot plot together
juli g. pausas [EMAIL PROTECTED] writes: Dear colleges, I'm trying to combine a barplot and a plot in a single figure as follows: data - 1:6 t - barplot(data, axes=F) par(new= T) plot(t, data, type=b) However, as you can see in the example, the dots of the second plot do not fall in the midpoint of the bars in the first. Any trick for setting the 2 plots at the same scale? I have unsuccessfully tried: plot(t, data, type=b, xlim=c(0,7)) plot(t, data, type=b, xlim=c(min(t),max(t))) (R 1.8.1, for Windows) The canonical trick for getting two plots on the same scale is to set xlim (and ylim) on *both*. On barplots, this gets a bit tricky since you have to leave room for the column width (the actual calculation can be read inside barplot.default). However, I'd try for something like t - barplot(data,names=1:6,ylim=range(c(0,data*1.01))) points(t, data, type=b) -- O__ Peter Dalgaard Blegdamsvej 3 c/ /'_ --- Dept. of Biostatistics 2200 Cph. N (*) \(*) -- University of Copenhagen Denmark Ph: (+45) 35327918 ~~ - ([EMAIL PROTECTED]) FAX: (+45) 35327907 __ [EMAIL PROTECTED] mailing list https://www.stat.math.ethz.ch/mailman/listinfo/r-help
Re: [R] barplot plot together
Thank you very much! I'm using par(new = TRUE) because in my real case, the 2 plots have different ylim (different y-scale). I got what I wanted by using the same xlim in the barplot and in the plot, as suggested by Peter. My real case: par(mar= c(7, 4, 5, 5) + 0.1) area - c(136, 3426, 5594, 29268, 19080, 31461, 72629, 225443)/ 1 nfires - c(48, 134, 80, 131, 27, 24, 23, 14) t - barplot(area, xlim=c(0.5,9.5), ylim=c(0, 25), ylab=Area burnt (x 1000 ha), xlab=Fire size class) box() par(new= T, yaxs = i, xpd=TRUE) plot(t, nfires, type=o, xlim=c(0.5,9.5), pch=19, ylim=c(0, 140), axes=F, xlab=, ylab=) axis(4); mtext(Number of fires, side=4, line=3, col=1) legend(2, 155, Number, lty= 1, pch= 19, bty=n, cex=0.8) legend(2, 163, Area, fill= 2, bty=n, cex=0.8) Cheers Juli Martin Maechler wrote: juli == juli g pausas [EMAIL PROTECTED] on Thu, 18 Dec 2003 10:54:08 +0100 writes: juli Dear colleges, juli I'm trying to combine a barplot and a plot in a single figure as follows: juli data - 1:6 juli t - barplot(data, axes=F) juli par(new= T) juli plot(t, data, type=b) juli However, as you can see in the example, the dots of juli the second plot do not fall in the midpoint of the juli bars in the first. Any trick for setting the 2 plots juli at the same scale? yes, use bd - barplot(data) points(bd, data, type = b) instead. A general recommendation: Try to *not* use par(new = TRUE) if you can. Martin -- Juli G. Pausas Centro de Estudios Ambientales del Mediterraneo (CEAM) C/ Charles R. Darwin 14, Parc Tecnologic, 46980 Paterna, Valencia, SPAIN Tel: (+ 34) 96 131 8227; Fax: (+ 34) 96 131 8190 mailto:[EMAIL PROTECTED] http://www.gva.es/ceam GCTE Fire Network - http://www.gva.es/ceam/FireNetwork [[alternative HTML version deleted]] __ [EMAIL PROTECTED] mailing list https://www.stat.math.ethz.ch/mailman/listinfo/r-help
Re: [R] barplot(names.arg) versus axis(labels)
On Fri, 2003-11-07 at 14:29, Siddique, Amer wrote: Should I be able to use axis() on a barplot? i have a data.frame, the first 3 values of which are: c[1:3,] median mean A156.5 58.5 A61 73.0 73.0 A62 63.0 63.0 str(c) `data.frame': 19 obs. of 2 variables: $ median: num 56.5 73 63 161 51 55 44.5 22 54 49 ... $ mean : num 58.5 73.0 63.0 161.0 47.5 ... if I do barplot(median) and then try to label the bars with axis(), I get; axis(1,,labels=rownames(c),font=4,cex=1) ^^ You have an error in your call to axis(). You are missing the 'at' argument. As a result, the default values of 'at' are set to axTicks(1), which in this case is returning 5 values. You have passed 19 values to the 'labels' argument in axis(). Hence the error message below. Error in axis(side, at, labels, tick, line, pos, outer, font, vfont, lty, : location and label lengths differ, 5 != 19 even though barplot(median, names.arg=rownames(c)) works and length(rownames(c)) [1] 19 In the above call to barplot(), you have specified the bar names, which will be matched within the function to the number of bars, thus it works. also when I attempt to place the value of the observation above the bar it does not space properly across all bars: text(median,labels=median,pos=3,cex=0.6) do i need to explicitly state an x-pos for the co-ord argument here? Yes. You get the proper x axis values by calling barplot() in the following fashion: mp - barplot() In this case, barplot() returns the bar midpoints and assigns them to 'mp'. Once you have that information, you can call text() with the x values set to 'mp'. See ?barplot for examples and you may wish to review the most recent R News, where there is an article on R's base graphics in R Help Desk. http://cran.r-project.org/doc/Rnews/Rnews_2003-2.pdf Just beware thoughthe author of that article has been known indulge in single malt scotches on Friday afternoons... ;-) HTH, Marc Schwartz __ [EMAIL PROTECTED] mailing list https://www.stat.math.ethz.ch/mailman/listinfo/r-help