plotCI() with ggplot2

461 views
Skip to first unread message

Sascha Vieweg

unread,
Mar 8, 2011, 10:34:15 AM3/8/11
to ggp...@googlegroups.com, r-h...@r-project.org
Hello

Currently, I plot some coefficients with some intervals using
function "plotCI()" (package "gplots") using the following code:

(m1 <- matrix(0:5, nrow=2, byrow=T, dimnames=list(c("v1", "v2"),
c("lo", "m", "hi"))))
m2 <- m1 + 1
library(gplots)
plotCI(
x=1:length(m1[, 1]),
pch="",
xlab="v1/v2",
xlim=c(1-.2, length(m1[, 1])+.2),
ylim=c(-.1, 7.1), yaxp=c(0, 7, 7),
ylab="Coefficients and intervals",
xaxt="n"
)
plotCI(
x=1:length(m1[, 1])-.1, y=m1[, 2], li=m1[, 1], ui=m1[, 3],
pt.bg="white", cex=1, lty=1, type="o", gap=0,
add=T
)
plotCI(
x=1:length(m2[, 1])+.1, y=m2[, 2], li=m2[, 1], ui=m2[, 3],
pch=10, pt.bg="white", cex=1, lty=1, type="o", gap=0,
add=T
)
axis(1, at=1:length(m1[, 1]), labels=NA)
text(1:length(m1[, 1]), -.2, c("v1", "v2"), cex=1, xpd=T,
adj=.5, srt=0)
abline(h=seq(0, 7, 1), col=gray(.7), lty="dotted", lwd=.85)
legend(1.9, 7.1,
legend=c(".7", ".5"),
title="Condition:",
cex=.8
)

I like to produce this plot with package "ggplot2", but I have
just discovered it and don't know where to start. It would be
great if somebody could give me a starting point with code for
that particular task.

Thanks, *S*

--
Sascha Vieweg, sasch...@gmail.com

ONKELINX, Thierry

unread,
Mar 8, 2011, 10:37:30 AM3/8/11
to Sascha Vieweg, ggp...@googlegroups.com, r-h...@r-project.org
Have a look at the examples of geom_errorbar() at the website: http://had.co.nz/ggplot2/geom_errorbar.html

Best regards,

Thierry

----------------------------------------------------------------------------
ir. Thierry Onkelinx
Instituut voor natuur- en bosonderzoek
team Biometrie & Kwaliteitszorg
Gaverstraat 4
9500 Geraardsbergen
Belgium

Research Institute for Nature and Forest
team Biometrics & Quality Assurance
Gaverstraat 4
9500 Geraardsbergen
Belgium

tel. + 32 54/436 185
Thierry....@inbo.be
www.inbo.be

To call in the statistician after the experiment is done may be no more than asking him to perform a post-mortem examination: he may be able to say what the experiment died of.
~ Sir Ronald Aylmer Fisher

The plural of anecdote is not data.
~ Roger Brinner

The combination of some data and an aching desire for an answer does not ensure that a reasonable answer can be extracted from a given body of data.
~ John Tukey

> -----Oorspronkelijk bericht-----
> Van: ggp...@googlegroups.com
> [mailto:ggp...@googlegroups.com] Namens Sascha Vieweg
> Verzonden: dinsdag 8 maart 2011 16:34
> Aan: ggp...@googlegroups.com; r-h...@r-project.org
> Onderwerp: plotCI() with ggplot2

> --
> 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
>

Kohske Takahashi

unread,
Mar 9, 2011, 3:52:14 AM3/9/11
to Scott Chamberlain, Sascha Vieweg, r-h...@r-project.org, ggp...@googlegroups.com
Hi,

try this:

d <- rbind(data.frame(M=1, v=1:2, m1), data.frame(M=2, v=1:2, m2))

ggplot(d, aes(v, ymin=lo, y=m, ymax=hi, colour=factor(M))) +
geom_line(position=position_dodge(width=0.1)) +
geom_pointrange(position=position_dodge(width=0.1))

--
Kohske Takahashi <takahash...@gmail.com>

Research Center for Advanced Science and Technology,
The University of  Tokyo, Japan.
http://www.fennel.rcast.u-tokyo.ac.jp/profilee_ktakahashi.html

On Wed, Mar 9, 2011 at 12:43 AM, Scott Chamberlain
<scttcham...@gmail.com> wrote:
> The code to use would be something like
>
> limits <- aes(ymax = y + se, ymin = y - se) # set error bar dimensions
>
> ggplot(yourdataframe, aes(x = x, y = y, colour = z)) +
> geom_point() +
> geom_errorbar(limits)

>> ______________________________________________
>> R-h...@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.
>>
>
>        [[alternative HTML version deleted]]
>
> ______________________________________________
> R-h...@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.
>

Adam_L...@keybank.com

unread,
Mar 9, 2011, 10:42:59 AM3/9/11
to ggp...@googlegroups.com

Hi group,

Is there an easy way to render a line connecting the means of boxplots when the x-axis is a factor? I've looked into using stat_summary, but nothing seems to work when the x-axis is a factor - does it violate some sort of standard to include a line?

Anyway, here's an example - I'm simply trying to show with a connecting line the comparison between the distribution for factor level x and that of factor level y.


tst<-data.frame(a=rnorm(1000),b=c(rep("x",50),rep("y",50)))

ggplot(tst,aes(b,a))+geom_boxplot()

Thanks very much.


Adam Loveland



Email Classification: KeyCorp Internal


This communication may contain privileged and/or confidential information. It
is intended solely for the use of the addressee. If you are not the intended
recipient, you are strictly prohibited from disclosing, copying, distributing
or using any of this information. If you received this communication in error,
please contact the sender immediately and destroy the material in its entirety,
whether electronic or hard copy. This communication may contain nonpublic personal
information about consumers subject to the restrictions of the 
Gramm-Leach-Bliley Act. You may not directly or indirectly reuse or redisclose
such information for any purpose other than to provide the services for which
you are receiving the information.

127 Public Square, Cleveland, OH 44114



If you prefer not to receive future e-mail offers for products or services from Key
send an e-mail to mailto:DNERe...@key.com with 'No Promotional E-mails' in the
SUBJECT line.

Ista Zahn

unread,
Mar 9, 2011, 11:01:48 AM3/9/11
to Adam_L...@keybank.com, ggp...@googlegroups.com
Hi Adam,
You probably need to set group=1 like this:

ggplot(tst,aes(b,a))+geom_boxplot() + geom_line(aes(group=1),
stat="summary", fun.y="mean")

Best,
Ista

> --
> 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
>

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

Adam_L...@keybank.com

unread,
Mar 9, 2011, 11:36:14 AM3/9/11
to Ista Zahn, ggp...@googlegroups.com

Thanks very much. Not sure why that didn't occur to me. :L





Adam Loveland




Ista Zahn <iz...@psych.rochester.edu>
Sent by: ista...@gmail.com

03/09/2011 11:01 AM

To
Adam_L...@keybank.com
cc
ggp...@googlegroups.com
Subject
Re: connect means of boxplots with factor x


Reply all
Reply to author
Forward
0 new messages