I would recommend not representing means by bars at all.
Bars are for counts, stacking from zero. Means are point estimates.
ggplot has a lot of routines for displaying means with errors bars:
geom_linerange, geom_pointrange. To hone your ggplot skills I
recommend looking into these geoms.
On Sep 11, 2009, at 4:32 PM, Felipe Carrillo wrote:
>
> Like this?
>
> # example using qplot
> library(ggplot2)
> meanprice <- tapply(diamonds$price, diamonds$cut, mean);meanprice
> cut <- factor(levels(diamonds$cut), levels = levels(diamonds$cut))
> qplot(cut, meanprice, geom="bar", stat="identity", fill
= I("grey50"))
> dev.new() # create a new graph to compare with qplot
> # Example using ggplot
> ggdata <- data.frame(meanprice,cut);ggdata
> ggplot(ggdata,aes(y=meanprice,x=cut)) +
> geom_bar(fill="grey50",stat='identity')
>
> Felipe D. Carrillo
> Supervisory Fishery Biologist
> Department of the Interior
> US Fish & Wildlife Service
> California, USA
>
>
> --- On Fri, 9/11/09, Andreas Christoffersen
> <achristoffersen at gmail.com> wrote:
>
>> From: Andreas Christoffersen <achristoffersen at gmail.com>
>> Subject: bar chart with means - using ggplot
>> To: "ggplot2" <ggplot2 at googlegroups.com>
>> Date: Friday, September 11, 2009, 1:50 PM
>>
>> In the help pages hadley provides the following example
>> showing how to
>> achieve bar charts with y being means of a variable instead
>> of counts.
>> The example uses qplot however - and not ggplot. Since i
>> would like to
>> understand ggplot better I would really like to see how
>> this could be
>> done in ggplot.
>>
>> # example using qplot
>> library(ggplot2)
>> meanprice <- tapply(diamonds$price, diamonds$cut, mean)
>> cut <- factor(levels(diamonds$cut), levels >>
levels(diamonds$cut))
>> qplot(cut, meanprice, geom="bar", stat="identity",
fill >> I("grey50"))
>>
>>>
>>
>
>
>
>
>
> --~--~---------~--~----~------------~-------~--~----~
> You received this message because you are subscribed to the ggplot2
> mailing list.
> To post to this group, send email to ggplot2 at googlegroups.com
> To unsubscribe from this group, send email to
> ggplot2+unsubscribe at googlegroups.com
> For more options, visit this group at
> http://groups.google.com/group/ggplot2
> -~----------~----~----~----~------~----~------~--~---
>
---------------------------
Dianne Cook
dicook at iastate.edu