Skip to content

ggplot2 plotting errorbars.

3 messages · Pieter Coussement, Rafael Robledo, Jeff Newmiller

#
Hi,
i'm using this lines of code:

dodge <-position_dodge(width=0.9)

ggplot(dfm,aes(x = X,y = value)) +
   geom_bar(aes(fill = variable), position=dodge, stat="identity") +
   geom_errorbar(aes(ymin=value-er, ymax=value+er),width=0.25, 
position=dodge,stat="identity")

to plot this data frame
                 X variable  value    er
1   A     X4  58.74  9.44
2  B     X4  52.41 10.01
3 C     X4  95.52  4.88
4  A     X1  75.51  8.54
5  B     X1   0.73 23.20
6 C     X1  96.66  1.18
7 A      X5  76.70  9.60
8 B      X5   0.56 34.50
9 C      X5 100.58 10.87

result:

As you see the error bars are still very much wrongly positioned.
How do i solve this?

thanks for the help!
#
Hi, it seems to be a problem about using aes both in ggplot as also in geom_bar.

You could specify fill property for your geom_bar in ggplot
initialization, in order to avoid this issue
(you could also do the same thing for ymin and ymax properties for
errorbar :P), i.e:

dodge <-position_dodge(width=0.9)

ggplot(dfm, aes(x=X, y=value, fill=variable, ymin=value-er, ymax=value+er)) +
  geom_bar(position=dodge) +
  geom_errorbar(position=dodge, width=0.25)

Hope it helps.
On Sun, Feb 3, 2013 at 5:01 PM, Pieter Coussement <dencoussie at gmail.com> wrote:
--
Rafael R.
On Sun, Feb 3, 2013 at 5:01 PM, Pieter Coussement <dencoussie at gmail.com> wrote:
--
Rafael R.
On Sun, Feb 3, 2013 at 5:01 PM, Pieter Coussement <dencoussie at gmail.com> wrote:
--
Rafael R.
On Sun, Feb 3, 2013 at 5:01 PM, Pieter Coussement <dencoussie at gmail.com> wrote:

  
    
#
I have no problem specifying the mapping in both ggplot and various geom_* functions. However, it is important to specify data and mapping parameter names in the geom_* functions, particularly so because the parameter ordering is different there.
---------------------------------------------------------------------------
Jeff Newmiller                        The     .....       .....  Go Live...
DCN:<jdnewmil at dcn.davis.ca.us>        Basics: ##.#.       ##.#.  Live Go...
                                      Live:   OO#.. Dead: OO#..  Playing
Research Engineer (Solar/Batteries            O.O#.       #.O#.  with
/Software/Embedded Controllers)               .OO#.       .OO#.  rocks...1k
--------------------------------------------------------------------------- 
Sent from my phone. Please excuse my brevity.
Rafael Robledo <xidddw at gmail.com> wrote: