[R] barplot names.arg
How can i set a rotation for the names.arg in barplot? __ 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
[R] barplot(names.arg) versus axis(labels)
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) 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 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? Thanks, Amer __ [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