Create graphs of odds ratio

414 views
Skip to first unread message

Nicippe B

unread,
Oct 30, 2013, 6:45:21 AM10/30/13
to ggp...@googlegroups.com
Hi All,

I have odds ratios with confidence limits which I want to plot in one graph on logarithmic scale. Based on some information available on web I have used the following code, but it did not produce what I really wanted. What I want is that;
1. All odds ratios should have the same colour
2. All estimates (the centre for each line)  should have the same symbol
3. No labelling of lags on the right side, so no factor(lag)  ( I don't know what that is called) .

Thanks in advance

ggplot(ddf, aes(x = lag, y = est, ymin = lcl, ymax = ucl)) +  geom_linerange(aes(col = factor(lag)), position=position_dodge(width=0.30)) +
geom_point(aes(shape = factor(lag)), position=position_dodge(width=0.30)) + ylab("Odds ratio & 95% CI") + geom_hline(aes(yintercept = 1)) + xlab("Lags") +scale_x_continuous(breaks=c(1:12),
labels=c(1:12),limits=c(1,12))

dput(oz)
structure(list(est = c(1.00259829132274, 1.00984590955515, 1.00103468123905, 
1.00487653316537, 1.01661914108823, 1.0117330149155, 0.998786945494639, 
1.00733107403491, 1.00356216944452, 1.00071264109382, 0.998962901445741, 
1.00986332731955), lcl = c(0.996222729695739, 1.00014827111742, 
0.990881659533582, 0.99728614205013, 1.00299985978141, 1.00018359042038, 
0.987787723766998, 0.995295107518125, 0.982501164372296, 0.967196805282684, 
0.982112817002489, 0.988975157702037), ucl = c(1.00901465485562, 
1.01963757824217, 1.01129173539759, 1.01252469509969, 1.03042335245412, 
1.0234158041323, 1.00990864584365, 1.01951258983543, 1.02507464058187, 
1.03538988608662, 1.01610208235615, 1.03119267650217), lag = c(1, 
2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12)), datalabel = "Written by R.              ", time.stamp = "30 Oct 2013 11:09", .Names = c("est", 
"lcl", "ucl", "lag"), formats = c("%9.0g", "%9.0g", "%9.0g", 
"%9.0g"), types = c(255L, 255L, 255L, 254L), val.labels = c("", 
"", "", ""), var.labels = c("est", "lcl", "ucl", ""), row.names = c("1", 
"2", "3", "4", "5", "6", "7", "8", "9", "10", "11", "12"), version = 12L, class = "data.frame")

Roman Luštrik

unread,
Oct 30, 2013, 7:04:53 AM10/30/13
to Nicippe B, ggplot2
Something like this?

ggplot(oz, aes(x = lag, y = est, ymin = lcl, ymax = ucl)) +  
  geom_linerange(position=position_dodge(width=0.30)) +
  geom_point(position=position_dodge(width=0.30)) + 
  ylab("Odds ratio & 95% CI") + 
  geom_hline(aes(yintercept = 1)) + xlab("Lags") +
  scale_x_continuous(breaks=c(1:12), labels=c(1:12),limits=c(1,12))

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/groups/opt_out.



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

Hualiang Lin

unread,
Oct 30, 2013, 7:15:38 AM10/30/13
to Nicippe B, ggp...@googlegroups.com

Another choice for your consideration:


ggplot(oz,aes(lag,est))+geom_point(size=3)+
  geom_errorbar(aes(ymin=lcl,ymax=ucl))+
  geom_hline(yintercept=1, size=0.15)+
  scale_x_continuous(breaks=c(1:12))+
  ylab('OR (95% CI)')  +
  xlab('Lag (days)')

Best

Hualiang


--

Nicippe B

unread,
Oct 30, 2013, 8:58:43 AM10/30/13
to Hualiang Lin, ggplot2
Thanks Roman and Hualiang for the quick reply. Both codes work and I have adopted a combination of your codes.  To change the size of the point I will use the option "geom_point(size=x)" , but how could I change the line size and colour? Any reading tips are appreciated.

Thanks

Roman Luštrik

unread,
Oct 30, 2013, 9:01:04 AM10/30/13
to Nicippe B, Hualiang Lin, ggplot2
Same logic, add size and colour arguments to geom_errorbar(). Be sure to check out the help file for examples and other arguments: http://docs.ggplot2.org/current/geom_errorbar.html

Cheers,
Roman


Reply all
Reply to author
Forward
0 new messages