Hello, I'm wondering how to set a value of mar ( par( mar=c(.......)) ) in order to allow labels to be visible in barplot. Is there any relation between the number of characters in a label and the second value of mar? Look at my example. x <- seq(20, 100, by=15) ety <- rep( "Effect on treatment group", times=length(x)) barplot(x, names.arg=ety, las=1, horiz=TRUE) Labels are not visible. But trial and error method with the second mar argument I get what I want. par(mar=c(3,12,2,1), cex=0.8) barplot(x, names.arg=ety, las=1, horiz=TRUE) I would like something like that: second.mar = max( nchar(ety) )/2 Taking the opportunity I have 2 another question: 1. Space between labels and bars is too big - how to change it to the value of 1 character? 2. In the example above the x axis is too short. How to make R draw a line little longer then maximum bar length. I know that I could set xlim=c(0,max(x)) but because of main increase equals 20 and the last value 95 it doesn't solve the problem. The increase is ok. but only line should be longer. Thank you Robert
Hello, Robert, see hints below. On Tue, 21 Dec 2010, Robert Ruser wrote:> Hello, > I'm wondering how to set a value of mar ( par( mar=c(.......)) ) in > order to allow labels to be visible in barplot. Is there any relation > between the number of characters in a label and the second value of > mar? Look at my example. > > x <- seq(20, 100, by=15) > ety <- rep( "Effect on treatment group", times=length(x)) > barplot(x, names.arg=ety, las=1, horiz=TRUE) > > Labels are not visible. But trial and error method with the second mar > argument I get what I want. > > par(mar=c(3,12,2,1), cex=0.8) > barplot(x, names.arg=ety, las=1, horiz=TRUE) > > I would like something like that: second.mar = max( nchar(ety) )/2Can't help with that really, but ...> Taking the opportunity I have 2 another question: > 1. Space between labels and bars is too big - how to change it to the > value of 1 character? > 2. In the example above the x axis is too short. How to make R draw a > line little longer then maximum bar length. I know that I could set > xlim=c(0,max(x)) but because of main increase equals 20 and the last > value 95 it doesn't solve the problem. The increase is ok. but only > line should be longer.You could take a look at par()'s argument mgp, but it affects both axes at the same time. I have the impression that you want more control of the style of each axis separately; axis() might than be useful, like par( mar = c( 3, 13, 2, 1), cex = 0.8) barplot( x, names.arg = NULL, horiz = TRUE, axes = FALSE) axis( side = 1, at = c( seq( 0, 80, by = 20), 95)) axis( side = 2, at = 1:length(ety), line = -1, las = 1, tick = FALSE, labels = ety) Hth, Gerrit> > > > Thank you > Robert > > ______________________________________________ > R-help at r-project.org mailing list > https://stat.ethz.ch/mailman/listinfo/r-help > PLEASE do read the posting guide http://www.R-project.org/posting-guide.html > and provide commented, minimal, self-contained, reproducible code.
Robert Ruser wrote:> > x <- seq(20, 100, by=15) > ety <- rep( "Effect on treatment group", times=length(x)) > barplot(x, names.arg=ety, las=1, horiz=TRUE) > > Labels are not visible. But trial and error method with the second mar > argument I get what I want. >Standard graphics has fallen a bit out of favor because of these quirks. Try lattice: library(lattice) x <- seq(20, 100, by=15) ety <- paste("Effect on treatment group",1:length(x)) barchart(ety~x) Note that the ety labels must be different to make this work. With your original data, you only get one bar (and I needed some time to find out what was wrong). Dieter -- View this message in context: http://r.789695.n4.nabble.com/labels-and-barchart-tp3141185p3145166.html Sent from the R help mailing list archive at Nabble.com.
2010/12/21 Gerrit Eichner <Gerrit.Eichner at math.uni-giessen.de>:> par( mar = c( 3, 13, 2, 1), cex = 0.8) > > barplot( x, names.arg = NULL, horiz = TRUE, axes = FALSE) > > axis( side = 1, at = c( seq( 0, 80, by = 20), 95)) > > axis( side = 2, at = 1:length(ety), line = -1, las = 1, tick = FALSE, > ? ? ?labels = ety)Thank you very much. I would change a little because the levels of the labels are not good. par( mar = c( 3, 13, 2, 1), cex = 0.8) my.chart <- barplot( x, names.arg = NULL, horiz = TRUE, axes = FALSE) axis( side = 1, at = c( seq( 0, 80, by = 20), 95)) axis( side = 2, at = my.chart, line = -1, las = 1, tick = FALSE, labels = ety)
2010/12/21 Dieter Menne <dieter.menne at menne-biomed.de>:> Standard graphics has fallen a bit out of favor because of these quirks. Try > lattice: > > library(lattice) > x <- seq(20, 100, by=15) > ety <- paste("Effect on treatment group",1:length(x)) > barchart(ety~x) > > Note that the ety labels must be different to make this work. With your > original data, you only get one bar (and I needed some time to find out what > was wrong).Thank you. I know that lattice in some circumstances is better but I find traditional graphics more controllable.