plot with 95% ci

47 views
Skip to first unread message

Christos Gkenas

unread,
Oct 5, 2015, 8:53:38 AM10/5/15
to ggplot2
Hi everyone! I am new to ggplot and I want to ask for some help
I have data from 2 different seasons (wet, dry) from 4 sites of 2 different species and I want to show them in one plot.The plot represents data from shannon diversity index
I have already calculated the mean and the 95% confidence intervals
The overall table looks like this

Season   Sites  Species H (mean)  +95%CI   -95%CI
wet          Ard     PK         0.69           0.84         0.55
dry          Ard      PK         0.39           0.64         0.22
wet         Ard      CL          0.96           1.15         0.72
dry          Ard      CL          0.68           0.93        0.47
wet         Gu       PK          0.64           0.84        0.43
dry          Gu       PK          0.65           0.78       0.52
wet         Gu       CL           1.07           1.22       0.89
dry          Gu       CL           1.17           1.36       0.96
wet         Dg       PK            0.92          1.03        0.82
dry         Dg        PK            0.91          1.09       0.71
wet        Vs         CL            0.96          1.12       0.79
dry         Vs         CL            0.94          1.09       0.75
I would like the plot to show the trend between seasons for every species without a line connecting the error bars.
Thanx for you help in advance

Best
Chris

Roman Luštrik

unread,
Oct 5, 2015, 8:59:08 AM10/5/15
to Christos Gkenas, ggplot2
Hi,

the way I see it you have two options:

or

See (references to) examples on both links. If you get stuck, feel free to drop another email.

Cheers,
Roman

--
--
You received this message because you are subscribed to the ggplot2 mailing list.
Please provide a reproducible example: https://github.com/hadley/devtools/wiki/Reproducibility
 
To post: email ggp...@googlegroups.com
To unsubscribe: email ggplot2+u...@googlegroups.com
More options: http://groups.google.com/group/ggplot2

---
You received this message because you are subscribed to the Google Groups "ggplot2" group.
To unsubscribe from this group and stop receiving emails from it, send an email to ggplot2+u...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.



--
In God we trust, all others bring data.

Christos Gkenas

unread,
Oct 5, 2015, 10:17:53 AM10/5/15
to ggplot2
Hi! thanx for your quick response. i am already doing some progress. However I have 2 questions. I calculated bootstrapped CI and the mean is not exactly in the middle point, how can I deal with this? and is there any command to tweak symbols?

Best
Chris

Roman Luštrik

unread,
Oct 5, 2015, 10:22:19 AM10/5/15
to Christos Gkenas, ggplot2
If you have two different CIs (and means) arrange in the same data.frame, where one column specifies from which method the data comes from, you can specify that coulmn in `shape` in `aes()` call. You can add points and their CIs through many geom_linerange (or whichever geom you're using) by specifying the data.frame, a la

geom_pointrange(data = df1, aes(...)) +
geom_pointrange(data = df2, aes(...)) +

Cheers,
Roman

--
--
You received this message because you are subscribed to the ggplot2 mailing list.
Please provide a reproducible example: https://github.com/hadley/devtools/wiki/Reproducibility
 
To post: email ggp...@googlegroups.com
To unsubscribe: email ggplot2+u...@googlegroups.com
More options: http://groups.google.com/group/ggplot2

---
You received this message because you are subscribed to the Google Groups "ggplot2" group.
To unsubscribe from this group and stop receiving emails from it, send an email to ggplot2+u...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Christos Gkenas

unread,
Oct 5, 2015, 8:34:22 PM10/5/15
to ggplot2
Thank you both for your help! I really appreciate it
I modified a little bit the routine you sent me

(p = ggplot(DF, aes(x = Season, y = H, color = Species, shape = Species)) +

scale_color_manual(values = c("black", "black")) +

scale_shape_manual(values = c(17, 0)) +

geom_pointrange(aes(ymin = LCL, ymax = UCL), size = 1,

position = position_dodge(width = 0.5)) +

theme_bw(base_size = 18) +

theme(panel.grid.major = element_blank(), panel.grid.minor = element_blank()) +

facet_wrap(~ Site, nrow = 1))


and produced the attached plot

I have only one question, do you know how to add caps to error bars?


Best


Chris


Τη Δευτέρα, 5 Οκτωβρίου 2015 - 1:53:38 μ.μ. UTC+1, ο χρήστης Christos Gkenas έγραψε:
Rplot.pdf

Mary Putt

unread,
Oct 5, 2015, 9:10:43 PM10/5/15
to ggp...@googlegroups.com
Checkout geom_errorbar instead of geom_pointrange.

http://docs.ggplot2.org/current/geom_errorbar.html
--
--
You received this message because you are subscribed to the ggplot2 mailing list.
Please provide a reproducible example: https://github.com/hadley/devtools/wiki/Reproducibility
 
To post: email ggp...@googlegroups.com
To unsubscribe: email ggplot2+u...@googlegroups.com
More options: http://groups.google.com/group/ggplot2

---
You received this message because you are subscribed to the Google Groups "ggplot2" group.
To unsubscribe from this group and stop receiving emails from it, send an email to ggplot2+u...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


-- 
Professor of Biostatistics
Graduate Program Chair, Biostatistics
Vice-Chair, Graduate Group in Epidemiology & Biostatistics
Perelman School of Medicine, University of Pennsylvania
621 Blockley Hall
423 Guardian Drive
Philadelphia, PA
19104
215-573-7020

Dennis Murphy

unread,
Oct 6, 2015, 1:25:07 AM10/6/15
to Mary Putt, ggplot2
Yes, but then one also has to plot the points explicitly with the same
amount of dodging, something like

ggplot(DF, aes(x = Season, y = H, shape = Species)) +
geom_point(size = 3, position = position_dodge(width = 0.5)) +
geom_errorbar(aes(ymin = LCL, ymax = UCL), size = 1,
position = position_dodge(width = 0.5)) +
facet_wrap(~ Site, nrow = 1)

Make the necessary changes to get the appearance you want; for
example, if you want the bars to be less (or more) prominent, use the
width = argument of geom_errorbar(), which is separate from the width
argument of position_dodge().

Dennis
Reply all
Reply to author
Forward
0 new messages