Dear list: I have some data for which I am generating a series of barplots for percentages. One issue that I am dealing with is that I am trying to get the legend to print in a fixed location for each chart generated by the data. Because these charts are being created in a loop, with different data, my code searches the data to identify the maximum value in the data and then print the data values 5 points above the tallest bar.
Now, in situations where the largest value is 100, I needed to create the y-axis high enough to accommodate the legend w/o crowding up the data or the bars. So, I have ylim =c(0,200) and then place the legend at c(2,150). Visually, this places things exactly where I want them. But, it seems silly to have a y-axis labeled as high as 200%. I'm certain there is a smarter technique. Is it possible to place the legend at a location higher than 100 to avoid the crowding of the bars and the data and then also have the labels for the y-axis not print after the value 100%? In looking at ?legend I didn't see an option that would address this. Below is some code that you can use to create a similar chart. Thanks, Harold math.bar <- c(53,31,55,28,55,100) apmxpmeet <- c(47, 50, 49, 50, 49, 46) par(ps=10) math.bar <- rbind(math.bar, apmxpmeet) math.barplot <- barplot(math.bar, beside=T, col=c('blue','orange'), names=c('Grade \n 3','Grade \n 4','Grade \n 5','Grade \n 6','Grade \n 7','Grade \n 8'), ylim=c(0,200), ylab="Percentage", xlab="Grade Level") tot <- round(math.bar,digits=0) graph.max <- max(math.bar, apmxpmeet, na.rm=T) text(math.barplot, graph.max+5, tot, xpd = TRUE, col = c("blue", "orange") ) legend(2,150,legend=(c("Label A", "Average")), fill=c("blue","orange")) [[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