[R] ggplot2 shifting bars to only overlap in groups

Hörmetjan Yiltiz hyiltiz at gmail.com
Thu Feb 12 16:38:01 CET 2015


You are most likely simply not running the whole lines of code: note that
the first line is:
N = 32

​Best
,
========================
He who is worthy to receive his days and nights is worthy to receive* all
else* from you (and me).
                                                 The Prophet, Gibran Kahlil


On Thu, Feb 12, 2015 at 11:31 PM, John Kane <jrkrideau at inbox.com> wrote:

> I am gettting the error"
> Error in rep_len(rep.int(seq_len(n), rep.int(k, n)), length) :
>   object 'N' not found
>
> Also your image did not come through.  Try sending it as a pdf file.
>
> when I try to create
> df<- data.frame(gender=gl(2,1,N, c("male","female")),
>           direction=gl(2,2,N, c("up","down")),
>           condition=gl(4,4,N, c("c1","c2","c3","c4")),
>           location=gl(2,16,N, c("east","west")),
>           t=rnorm(N, 1, 0.5),
>           ci=abs(rnorm(N, 0, 0.2)))
>
> John Kane
> Kingston ON Canada
>
>
> > -----Original Message-----
> > From: hyiltiz at gmail.com
> > Sent: Thu, 12 Feb 2015 22:08:36 +0800
> > To: r-help at r-project.org
> > Subject: [R] ggplot2 shifting bars to only overlap in groups
> >
> > Hi all,
> >
> > I have four factors for a continuous time variable along with its
> > confidence interval. I would like to produce a publication quality error
> > bar chart that is clear to understand. For now, I used colors, x axis
> > position, facets and alpha level to distinguish them.
> >
> > I would like to overlap each pairs of bars with the same color a bit as a
> > group, but not overlap each and every bars with each other.
> >
> > Here is a minimal example:
> >
> > N = 32
> > df<- data.frame(gender=gl(2,1,N, c("male","female")),
> >           direction=gl(2,2,N, c("up","down")),
> >           condition=gl(4,4,N, c("c1","c2","c3","c4")),
> >           location=gl(2,16,N, c("east","west")),
> >           t=rnorm(N, 1, 0.5),
> >           ci=abs(rnorm(N, 0, 0.2)))
> > pp <-
> >   ggplot(df, aes(x=gender, y=t, fill=condition, alpha=direction)) +
> >   facet_grid(location~.) +
> >   geom_bar(position=position_dodge(.9), stat="identity", color="black") +
> >   geom_errorbar(aes(ymin=t-ci, ymax=t+ci),
> >                 width=.2,                    # Width of the error bars
> >                 position=position_dodge(.9)) +
> >   scale_alpha_discrete(range= c(0.4, 1))
> > pp
> >
> >
> >
> > In the attachment, I have added the output figure, while manually editing
> > the SVG file to make the lower-left group of bars to make them as I
> > wanted.
> > (The spacing in between each pair is not necessarily required.)
> >
> >
> > ​Best
> > ,
> > ========================
> > He who is worthy to receive his days and nights is worthy to receive* all
> > else* from you (and me).
> >                                                  The Prophet, Gibran
> > Kahlil
> > ______________________________________________
> > R-help at r-project.org mailing list -- To UNSUBSCRIBE and more, see
> > 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.
>
> ____________________________________________________________
> Can't remember your password? Do you need a strong and secure password?
> Use Password manager! It stores your passwords & protects your account.
> Check it out at http://mysecurelogon.com/password-manager
>
>
>

	[[alternative HTML version deleted]]



More information about the R-help mailing list