Re: [R] plotCI() with ggplot2

From: Kohske Takahashi <takahashi.kohske_at_gmail.com>
Date: Wed, 09 Mar 2011 17:52:14 +0900

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 <takahashi.kohske_at_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
<scttchamberlain4_at_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)
>
>
>
> On Tuesday, March 8, 2011 at 9:34 AM, Sascha Vieweg wrote:
>> 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, saschaview_at_gmail.com
>>
>> ______________________________________________
>> R-help_at_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-help_at_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.
>
______________________________________________ R-help_at_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.
Received on Wed 09 Mar 2011 - 09:30:59 GMT

Archive maintained by Robert King, hosted by the discipline of statistics at the University of Newcastle, Australia.
Archive generated by hypermail 2.2.0, at Wed 09 Mar 2011 - 09:40:20 GMT.

Mailing list information is available at https://stat.ethz.ch/mailman/listinfo/r-help. Please read the posting guide before posting to the list.

list of date sections of archive