plot(b$acf,type="h") in ggplot

479 views
Skip to first unread message

ran2

unread,
May 19, 2010, 11:43:38 AM5/19/10
to ggplot2
Dear all,

maybe i am just sitting too long in front of my computer (or simply
not long enough), but i can´t get it done:

i´d like to plot something like the following with ggplot:

plot(b$acf,type="h")

What I do in ggplot is:

qplot(lag,acf,data=d)
+geom_hline(yintercept=0,color="red",alpha=0.9,size=0.2)
+geom_hline(yintercept=qnorm((1 + 0.95)/2)/sqrt(b
$n.used),color="blue") +geom_hline(yintercept=(qnorm((1 + 0.95)/2)/
sqrt(b$n.used))*(-1),color="blue")

which gives me a nice plot with all the CI stuff that plot.acf offers.
Unfortunately I just dots, or lines. The "bars" geom does not work or
is not supposed to work with this. I need to get the lags visualized
as bars instead of points. In this case the bars are not frequencies
like in histograms.

Thx for any help on advance

best

matt

--
You received this message because you are subscribed to the ggplot2 mailing list.
Please provide a reproducible example: http://gist.github.com/270442

To post: email ggp...@googlegroups.com
To unsubscribe: email ggplot2+u...@googlegroups.com
More options: http://groups.google.com/group/ggplot2

Luciano Selzer

unread,
May 19, 2010, 12:16:52 PM5/19/10
to ran2, ggplot2
Hi Matt, maybe you could use geom_linerange and make ymin = 0 and ymax = acf ? That should the trick.

Cheers
Luciano


ran2

unread,
May 19, 2010, 12:39:33 PM5/19/10
to ggplot2
Hi Luciano,

thanks for the hint. unfortunately it did not help, looks similar to a
histogram with binwidth=0.1
i tried the following:

qplot(lag,acf,data=d, geom="linerange",ymin=min(acf),ymax=max(acf))
+geom_hline(yintercept=0,color="red",alpha=0.9,size=0.2)

and all i get is vertical lines from the max to the min of acf, which
look all the same for every lag...


On May 19, 6:16 pm, Luciano Selzer <luciano.sel...@gmail.com> wrote:
> Hi Matt, maybe you could use geom_linerange and make ymin = 0 and ymax = acf
> ? That should the trick.
>
> Cheers
> Luciano
>
> 2010/5/19 ran2 <matthias.bann...@googlemail.com>
>
>
>
> > Dear all,
>
> > maybe i am just sitting too long in front of my computer (or simply
> > not long enough), but i can´t get it done:
>
> > i´d like to plot something like the following with ggplot:
>
> > plot(b$acf,type="h")
>
> > What I do in ggplot is:
>
> > qplot(lag,acf,data=d)
> > +geom_hline(yintercept=0,color="red",alpha=0.9,size=0.2)
> > +geom_hline(yintercept=qnorm((1 + 0.95)/2)/sqrt(b
> > $n.used),color="blue") +geom_hline(yintercept=(qnorm((1 + 0.95)/2)/
> > sqrt(b$n.used))*(-1),color="blue")
>
> > which gives me a nice plot with all the CI stuff that plot.acf offers.
> > Unfortunately I just dots, or lines. The "bars" geom does not work or
> > is not supposed to work with this. I need to get the lags visualized
> > as bars instead of points. In this case the bars are not frequencies
> > like in histograms.
>
> > Thx for any help on advance
>
> > best
>
> > matt
>
> > --
> > You received this message because you are subscribed to the ggplot2 mailing
> > list.
> > Please provide a reproducible example:http://gist.github.com/270442
>
> > To post: email ggp...@googlegroups.com
> > To unsubscribe: email ggplot2+u...@googlegroups.com<ggplot2%2Bunsu...@googlegroups.com>

ran2

unread,
May 19, 2010, 12:51:35 PM5/19/10
to ggplot2
Finally I found a solution on my own, thanks to Hadley´s
documentation!

qplot(lag,acf,data=d,geom="bar",stat="identity")

does the trick for me, though I get an error message like: Stacking
not well defined when ymin != 0

Would be nice to get rid of that msg, bu in the end it works and looks
better than Johnny Bravo :)



On May 19, 6:16 pm, Luciano Selzer <luciano.sel...@gmail.com> wrote:
> Hi Matt, maybe you could use geom_linerange and make ymin = 0 and ymax = acf
> ? That should the trick.
>
> Cheers
> Luciano
>
> 2010/5/19 ran2 <matthias.bann...@googlemail.com>
>
>
>
> > Dear all,
>
> > maybe i am just sitting too long in front of my computer (or simply
> > not long enough), but i can´t get it done:
>
> > i´d like to plot something like the following with ggplot:
>
> > plot(b$acf,type="h")
>
> > What I do in ggplot is:
>
> > qplot(lag,acf,data=d)
> > +geom_hline(yintercept=0,color="red",alpha=0.9,size=0.2)
> > +geom_hline(yintercept=qnorm((1 + 0.95)/2)/sqrt(b
> > $n.used),color="blue") +geom_hline(yintercept=(qnorm((1 + 0.95)/2)/
> > sqrt(b$n.used))*(-1),color="blue")
>
> > which gives me a nice plot with all the CI stuff that plot.acf offers.
> > Unfortunately I just dots, or lines. The "bars" geom does not work or
> > is not supposed to work with this. I need to get the lags visualized
> > as bars instead of points. In this case the bars are not frequencies
> > like in histograms.
>
> > Thx for any help on advance
>
> > best
>
> > matt
>
> > --
> > You received this message because you are subscribed to the ggplot2 mailing
> > list.
> > Please provide a reproducible example:http://gist.github.com/270442
>
> > To post: email ggp...@googlegroups.com
> > To unsubscribe: email ggplot2+u...@googlegroups.com<ggplot2%2Bunsu...@googlegroups.com>

Luciano Selzer

unread,
May 19, 2010, 1:03:59 PM5/19/10
to ran2, ggplot2
Well, it works if you make ymin = 0 and omit y.
qplot(lag, ymin = 0, ymax = acf, data = d, geom="linerange")

That's more similar to the acf plot if that's what you are looking for...

Cheers
Luciano


2010/5/19 ran2 <matthias...@googlemail.com>
Finally I found a solution on my own, thanks to Hadley´s

Hadley Wickham

unread,
May 19, 2010, 1:07:04 PM5/19/10
to ran2, ggplot2
On Wed, May 19, 2010 at 9:51 AM, ran2 <matthias...@googlemail.com> wrote:
> Finally I found a solution on my own, thanks to Hadley´s
> documentation!
>
> qplot(lag,acf,data=d,geom="bar",stat="identity")
>
> does the trick for me, though I get an error message like: Stacking
> not well defined when ymin != 0

Try position ="identity" as well.

Hadley

--
Assistant Professor / Dobelman Family Junior Chair
Department of Statistics / Rice University
http://had.co.nz/

ran2

unread,
May 20, 2010, 6:05:26 AM5/20/10
to ggplot2
thx! using both, position and stat worked well.

qplot(lag,acf,data=d,geom="bar",stat="identity",position="identity")

Is there a possibility to control the width of the bars? (because
binwidth does not work and I do not know others commands :) . anyway,
it´s just minor blemish - i hope i´ll find something in the
documentation.

matt


On May 19, 7:07 pm, Hadley Wickham <had...@rice.edu> wrote:
> On Wed, May 19, 2010 at 9:51 AM, ran2 <matthias.bann...@googlemail.com> wrote:
> > Finally I found a solution on my own, thanks to Hadley´s
> > documentation!
>
> > qplot(lag,acf,data=d,geom="bar",stat="identity")
>
> > does the trick for me, though I get an error message like: Stacking
> > not well defined when ymin != 0
>
> Try position ="identity" as well.
>
> Hadley
>
> --
> Assistant Professor / Dobelman Family Junior Chair
> Department of Statistics / Rice Universityhttp://had.co.nz/

Hadley Wickham

unread,
May 22, 2010, 12:15:55 PM5/22/10
to ran2, ggplot2
> qplot(lag,acf,data=d,geom="bar",stat="identity",position="identity")
>
> Is there a possibility to control the width of the bars? (because
> binwidth does not work and I do not know others commands :) . anyway,
> it´s just minor blemish - i hope i´ll find something in the
> documentation.

binwidth should work - can you please provide a small reproducible example?

Thanks,
Reply all
Reply to author
Forward
0 new messages