[R] ggplot question: changing the label for the Y axis on a histogram

Ista Zahn izahn at psych.rochester.edu
Mon Jul 25 21:49:44 CEST 2011


Hi Steven,
It works as expected for me (see session info below). What version of
R and ggplot are you using?

Best,
Ista

sessionInfo()
R version 2.13.0 (2011-04-13)
Platform: i386-pc-mingw32/i386 (32-bit)

locale:
[1] LC_COLLATE=English_United States.1252
[2] LC_CTYPE=English_United States.1252
[3] LC_MONETARY=English_United States.1252
[4] LC_NUMERIC=C
[5] LC_TIME=English_United States.1252

attached base packages:
 [1] grid      stats4    splines   stats     graphics  grDevices utils
 [8] datasets  methods   base

other attached packages:
 [1] gridExtra_0.8     ggplot2_0.8.9     reshape_0.8.4     plyr_1.5.2
 [5] ascii_1.4         proto_0.3-9.2     robustbase_0.7-6  Hmisc_3.8-3
 [9] party_0.9-99992   vcd_1.2-11        colorspace_1.1-0  MASS_7.3-12
[13] strucchange_1.4-4 sandwich_2.2-7    zoo_1.6-5         coin_1.0-18
[17] ca_0.33           rgl_0.92.798      psych_1.0-98      modeltools_0.2-17
[21] mvtnorm_0.9-9991  survival_2.36-9

loaded via a namespace (and not attached):
[1] cluster_1.14.0  lattice_0.19-26 tools_2.13.0

On Mon, Jul 25, 2011 at 3:24 PM, Steven Rytina, Prof.
<steven.rytina at mcgill.ca> wrote:
> Thanks for taking a look.
>
>        As you can see from my (reduced) example below, I am drawing on counts and then asking bin to aggregate.
>        My hunch is that ylab() somehow gets over-ridden in the collaboration implicit in geom_histogram.
>
>        Accordingly, any comment that illuminates the actual mechanics invoked by this (and how to examine them) would be much appareciated.
>
> vals<-c(-2.601,-2.073,-1.341,-1.126,-1.022,-0.847,-0.839,-0.791,-0.790,-0.683,-0.572,-0.556,-0.538,-0.454,-0.394,-0.342,-0.313,-0.184,- 0.138,0.302,0.307
>                ,0.364,0.796,0.830,0.992,1.029,1.305,1.334)
>        cnts<-c(186.8,541.0,221.5,191.2,545.6,317.9,375.6,335.5,154.4,199.1,305.1,302.4,179.2,164.8,155.0,281.4,158.6,560.3,208.6,164.1,157.2
>                ,505.2,1282.9,181.6,273.0,315.3,166.9,222.8)
>        qdata<-as.data.frame(cbind(vals,cnts))
>        qplot(vals,weight=cnts,data=qdata,binwidth=.29,main="test")+ylab("NEW")
>
> -----Original Message-----
> From: istazahn at gmail.com [mailto:istazahn at gmail.com] On Behalf Of Ista Zahn
> Sent: Monday, July 25, 2011 2:02 PM
> To: Steven Rytina, Prof.
> Cc: r-help at r-project.org
> Subject: Re: [R] ggplot question: changing the label for the Y axis on a histogram
>
> Hi Steven,
> The basic example works:
>
> qplot(rnorm(100)) + ylab("Bin Counts")
>
> Please post a reproducible example that illustrates the problem you are having.
>
> Best,
> Ista
>
> On Mon, Jul 25, 2011 at 1:40 PM, Steven Rytina, Prof.
> <steven.rytina at mcgill.ca> wrote:
>> Some help with how to re-label the vertical axis in a histogram  would be appreciated.
>>
>>                qplot(off.sc,weight=rel.freq,binwidth=.29,main="test Figure"+ylab("New from inside"))+ylab("New from outside")+
>>                                                                xlab("off.sc\nAggregated frequency plots for 17 equal intervals.")
>>
>> The code produces a proper histogram. However, the y axis is labeled count
>>                and this needs to be changed because the data is relative frequencies (sample proportions.)
>> ylab() does not do the trick (in either position). Does anyone know what works?
>>
>>                Thanks
>>                Steve Rytina, McGill University
>>
>>        [[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.
>>
>
>
>
> --
> Ista Zahn
> Graduate student
> University of Rochester
> Department of Clinical and Social Psychology
> http://yourpsyche.org
>
> ______________________________________________
> 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.
>



-- 
Ista Zahn
Graduate student
University of Rochester
Department of Clinical and Social Psychology
http://yourpsyche.org



More information about the R-help mailing list