Re: [R] ggplot - Setting the y-scale in a bar plot

From: hadley wickham <h.wickham_at_gmail.com>
Date: Tue, 11 Dec 2007 15:15:07 -0600

Hi Pedro,

What's the problem exactly? You'll need to compute the range yourself, and then use scale_y_continuous as you have below.

(Also you can abbreviate the bar chart plotting command to: qplot(x, y, data=plotdata, geom="bar", stat="identity"))

Hadley

On 12/11/07, Pedro de Barros <pbarros_at_ualg.pt> wrote:
> Dear All (probably Hadley),
>
> I am now trying to customise some plots using a bar geom.
>
> I do not want to use the default binning statistic, but rather
> calculate the bar heigths separately. I do manage this, but for
> comparison purposes I would like to have a set of plots all with the
> same y-axis height. But I do not seem to find out how to fix the
> scale of the y-axis in this case.
> Any tips?
> Using R 2.6.1 on Windows.
>
> Thanks for any help,
> Pedro
>
> I attach below the code I am using:
> plotdata<-data.frame(x=factor(2:8), y=0.1*(2:8))
> plot1<-ggplot()
> plot1<-plot1+layer(data=plotdata,
> mapping=aes_string(x='x',y='y'),geom='bar', stat='identity')
>
> RangeY <-c(0,1)
> YBreaks <- (0:10)*diff(RangeY)/10
> YTickLabels<- as.character(YBreaks)
>
> plot2 <- plot1 + scale_y_continuous(limits=RangeY, breaks=YBreaks,
> labels=YTickLabels, expand=c(0,0))
> print(plot2)
>
> ______________________________________________
> 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.
>

-- 
http://had.co.nz/

______________________________________________
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.
Received on Tue 11 Dec 2007 - 21:18:42 GMT

Archive maintained by HREF="http://tolstoy.newcastle.edu.au/~rking/">Robert King, hosted by the discipline of statistics at the University of Newcastle, Australia.
Archive generated by hypermail 2.2.0, at Tue 11 Dec 2007 - 22:30:18 GMT.

Mailing list information is available at https://stat.ethz.ch/mailman/listinfo/r-help. Please read the posting guide before posting to the list.