Benedikt Drosse
2011-Sep-22 15:49 UTC
[R] How to adjust the y-axis range in barplot properly
Hello R-Users, it might be a rather simple problem I have, but I couldn't find any solution online. Thus, here is my problem: I would like to adjust the y-axis range in a barplot, since all my values are >70. Therefore I would like to only visualize the y-axis from 60-100 (example 1). The problem is, the range of the y-axis is adjusted, but the barsize stays the same and vanishes from the plot area. How can I "cut" the y-axis and the bars in a proper way. Unfortunatlely I dit not get "gap.barplot" function to work on the matrix in example 1. I would be very greatful for some ideas and help, cheers, Benedikt example 1: data <- as.matrix(rbind(c(85:90), c(75:80))) barplot(data, beside=TRUE) barplot(data, ylim=c(60,90), beside=TRUE)
This should do the trick: barplot(data, ylim=c(60,90), beside=TRUE, xpd = FALSE) As usual, check ?barplot first for clues on how to customize the plot to your specifications. On Thu, Sep 22, 2011 at 11:49 AM, Benedikt Drosse <drosse at mpipz.mpg.de> wrote:> > Hello R-Users, > it might be a rather simple problem I have, but I couldn't find any solution online. Thus, here is my problem: > > I would like to adjust the y-axis range in a barplot, since all my values are >70. Therefore I would like to only visualize the y-axis from 60-100 (example 1). > The problem is, the range of the y-axis is adjusted, but the barsize stays the same and vanishes from the plot area. > How can I "cut" the y-axis and the bars in a proper way. Unfortunatlely I dit not get "gap.barplot" function to work on the matrix in example 1. > > I would be very greatful for some ideas and help, > cheers, > Benedikt > > example 1: > data <- as.matrix(rbind(c(85:90), c(75:80))) > barplot(data, beside=TRUE) > barplot(data, ylim=c(60,90), beside=TRUE) > > ______________________________________________ > 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.-- ___________________________ Luke Miller Postdoctoral Researcher Marine Science Center Northeastern University Nahant, MA (781) 581-7370 x318
On 09/23/2011 01:49 AM, Benedikt Drosse wrote:> Hello R-Users, > it might be a rather simple problem I have, but I couldn't find any > solution online. Thus, here is my problem: > > I would like to adjust the y-axis range in a barplot, since all my > values are >70. Therefore I would like to only visualize the y-axis from > 60-100 (example 1). > The problem is, the range of the y-axis is adjusted, but the barsize > stays the same and vanishes from the plot area. > How can I "cut" the y-axis and the bars in a proper way. Unfortunatlely > I dit not get "gap.barplot" function to work on the matrix in example 1. >Hi Benedikt, The gap.*plot functions are intended to create a gap between two or more sets of values with ranges that don't overlap, such that there would be large empty spaces on the plot. When you just want to start the ordinate above zero, you can do this: barp(data,ylim=c(60,100),col=2:3,height.at=c(70,80,90,100)) axis.break(2,65) or if you really want the gap in there: barp(data,ylim=c(60,100),col=2:3,height.at=c(60,70,80,90,100), height.lab=c(0,70,80,90,100)) axis.break(2,65,style="gap") Jim