Re: [R] break error bars in ggplot2

2011-11-15 Thread Fischer, Felix
Dear Ben,

great, works fine! I guess, the error occurs because data outside the scale 
limits "is thrown away" as stated in ?coord_cartesian .

Thanks,

Felix


From: Ben Bolker 
mailto:bbolker_at_gmail.com?Subject=Re:%20[R]%20break%20error%20bars%20in%20ggplot2>>
Date: Tue, 15 Nov 2011 13:44:44 +

Fischer, Felix  charite.de> writes:

>
> Hello, 
>
> i use ggplot to plot some measures including CIs as horizontal
> errorbars. I get an error when the scale
> limits are narrower than the boundaries of the error bar and
> hence the CIs are not plotted.
>
> library(ggplot2)
> df <- data.frame(resp=c(1,2), k=c(1,2), se=c(1,2))
>
> ggplot(df, aes(resp,y=k)) + geom_point() +
> geom_errorbarh(aes(xmax = resp + se, xmin = resp - se)) +
> scale_x_continuous(limits=c(-1,3))
>
> Is there a way to plot the errorbars anyway? Setting
> xmax to the scale limit is not so good, I guess, because
> you couldn't determine whether the CI is wider than the scale limits or not.

  I'm not sure I completely understand your last paragraph, but I think you 
want to substitute

  coord_cartesian(xlim=c(-1,3))

for your scale_x_continuous() component; as discussed in the ggplot2 book, 
limits set on scales act differently than limits set on coordinate systems. 
(I'm a little surprised you get an error, though.)

  There's a very active ggplot2 google group that might be best for 
ggplot(2)-specific questions ...

[[alternative HTML version deleted]]

__
R-help@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.


Re: [R] break error bars in ggplot2

2011-11-15 Thread Ben Bolker
Fischer, Felix  charite.de> writes:

> 
> Hello,
> 
> i use ggplot to plot some measures including CIs as horizontal 
> errorbars. I get an error when the scale
> limits are narrower than the boundaries of the error bar and
>  hence the CIs are not plotted.
> 
> library(ggplot2)
> df <- data.frame(resp=c(1,2), k=c(1,2), se=c(1,2))
> 
> ggplot(df, aes(resp,y=k)) +  geom_point() + 
>   geom_errorbarh(aes(xmax = resp + se, xmin = resp - se)) +  
> scale_x_continuous(limits=c(-1,3))
> 
> Is there a way to plot the errorbars anyway? Setting 
> xmax to the scale limit is not so good, I guess, because
> you couldn't determine whether the CI is wider than the scale limits or not.

  I'm not sure I completely understand your last paragraph, but
I think you want to substitute

  coord_cartesian(xlim=c(-1,3))

for your scale_x_continuous() component; as discussed in the ggplot2
book, limits set on scales act differently than limits set on 
coordinate systems.  (I'm a little surprised you get an error, though.)

  There's a very active ggplot2 google group that might be best
for ggplot(2)-specific questions ...

__
R-help@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] break error bars in ggplot2

2011-11-15 Thread Fischer, Felix
Hello,

i use ggplot to plot some measures including CIs as horizontal errorbars. I get 
an error when the scale limits are narrower than the boundaries of the error 
bar and hence the CIs are not plotted.

library(ggplot2)
df <- data.frame(resp=c(1,2), k=c(1,2), se=c(1,2))

ggplot(df, aes(resp,y=k)) +  geom_point() + geom_errorbarh(aes(xmax = resp + 
se, xmin = resp - se)) +   scale_x_continuous(limits=c(-1,3))

Is there a way to plot the errorbars anyway? Setting xmax to the scale limit is 
not so good, I guess, because you couldn't determine whether the CI is wider 
than the scale limits or not.

Thanks a lot,
Best,
Felix



Dr. rer. nat. Dipl.-Psych. Felix Fischer
Institut für Sozialmedizin, Epidemiologie und Gesundheitsökonomie
Charité - Universitätsmedizin Berlin
Luisenstrasse 57
10117 Berlin

Tel: 030 450 529 104
Fax: 030 450 529 902
http://epidemiologie.charite.de


[[alternative HTML version deleted]]

__
R-help@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.