Dear all As a new user of R, can someone please help me with the following I have created a programme to analyse laboratory data and one of the graphs is a bar plot of 'Z' scores. On the bar plot I am using the following line to plot some results barplot (zb[,c("ZBW")], ylim = c(-6,6), names.arg=zb[,c("LabNo")],xlab="Lab Code Number", cex.names = .5 , axis.lty=1 , main = " Total Coliform ") What I would like to do is move the xlab parameter to sit on top or on each bar and not on the x-axis at y=0. Any help would be appreciated. Thanks Steve [[alternative HTML version deleted]]
on 02/09/2009 03:21 PM Steve Sidney wrote:> Dear all > > As a new user of R, can someone please help me with the following > > I have created a programme to analyse laboratory data and one of the > graphs is a bar plot of 'Z' scores. > > On the bar plot I am using the following line to plot some results > > barplot (zb[,c("ZBW")], ylim = c(-6,6), > names.arg=zb[,c("LabNo")],xlab="Lab Code Number", cex.names = .5 , > axis.lty=1 , main = " Total Coliform ") > > What I would like to do is move the xlab parameter to sit on top or > on each bar and not on the x-axis at y=0. > > Any help would be appreciated.If the 'Z' scores are the typical standard deviation based continuous Z scores, rather than a barplot, I would recommend a dotchart or point based plot. Barplots are best suited for count/frequency based data. See ?dotchart. With respect to the barplot, the key piece of information to know is that barplot() returns the bar midpoints, which you need to know for subsequent text placement. This is described in ?barplot. Something like this should get you there: # For reproducibility set.seed(1) # Generate a sample of LETTERS L <- sample(LETTERS[1:5], 100, replace = TRUE) # Create a frequency table TL <- table(L)> TLL A B C D E 13 25 19 26 17 # Create the barplot, set ylim to make room for the text # set names.arg so that nothing appears below the x axis mp <- barplot(TL, ylim = c(0, 30), names.arg = NA) # What's in mp?> mp[,1] [1,] 0.7 [2,] 1.9 [3,] 3.1 [4,] 4.3 [5,] 5.5 # Now draw the text at x = mp; y = TL positions. # Set 'pos' to move the values above the bars text(mp, TL, labels = names(TL), pos = 3) # If you wanted the counts above the bars instead of the labels: text(mp, TL, labels = TL, pos = 3) HTH, Marc Schwartz
Hi, #There are a lot of examples for barplot if you just type example(barplot) # i altered one slightly to put the values on top of each bar mp <- barplot(VADeaths) # default #tot <- colMeans(VADeaths) #changed this line tot = colSums(VADeaths) #wether you need max, min, mean , colSums will depend on your data text(mp, tot + 4, format(tot), xpd = TRUE, col = "blue") #you should be able to get it from here Thomas Steve Sidney schrieb:> Dear all > > As a new user of R, can someone please help me with the following > > I have created a programme to analyse laboratory data and one of the graphs is a bar plot of 'Z' scores. > > On the bar plot I am using the following line to plot some results > > barplot (zb[,c("ZBW")], ylim = c(-6,6), names.arg=zb[,c("LabNo")],xlab="Lab Code Number", cex.names = .5 , axis.lty=1 , main = " Total Coliform ") > > What I would like to do is move the xlab parameter to sit on top or on each bar and not on the x-axis at y=0. > > Any help would be appreciated. > > Thanks > > Steve > [[alternative HTML version deleted]] > > ______________________________________________ > 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. > >