Re: [R] annotate

2023-10-05 Thread Paul Murrell

Hi

You could use the 'gggrid' package, which gets you access to other 
coordinate systems.  For example, the following places the text labels 
2mm above the (centres of the) data points (bottom-justified) ...



library(gggrid)

labels <- function(data, coords) {
textGrob(data$label,
 coords$x,
 unit(coords$y, "npc") + unit(2, "mm"),
 just="bottom")
}

ggplot(faithful, aes(x = eruptions, y = waiting)) +
geom_point(shape=21, size=3, fill="orange") +
geom_hline(yintercept = 92) +
grid_panel(labels,
   data = above_92,
   mapping = aes(x = eruptions, y = waiting,
 label = waiting)) +
theme_cowplot()


Hope that helps.

Paul

On 5/10/2023 8:34 am, Subia Thomas OI-US-LIV5 wrote:

Colleagues,

I wish to create y-data labels which meet a criterion.

Here is my reproducible code.
library(dplyr)
library(ggplot2)
library(cowplot)

above_92 <- filter(faithful,waiting>92)

ggplot(faithful,aes(x=eruptions,y=waiting))+
geom_point(shape=21,size=3,fill="orange")+
theme_cowplot()+
geom_hline(yintercept = 92)+
annotate(geom="text",x=above_92$eruptions,y=above_92$waiting+2,label=above_92$waiting)

A bit of trial and error is required to figure out what number to add or 
subtract to above_92$waiting.


Is there a more efficient way to do this?


Thomas Subia
Lean Six Sigma Senior Practitioner

DRÄXLMAIER Group
DAA Draexlmaier Automotive of America LLC

mailto:thomas.su...@draexlmaier.com
http://www.draexlmaier.com 



"Nous croyons en Dieu.
Tous les autres doivent apporter des données.
Edward Deming


Public: All rights reserved. Distribution to third parties allowed.

__
R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see
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.


--
Dr Paul Murrell
Te Kura Tatauranga | Department of Statistics
Waipapa Taumata Rau | The University of Auckland
Private Bag 92019, Auckland, New Zealand
64 9 3737599 x85392
p...@stat.auckland.ac.nz
www.stat.auckland.ac.nz/~paul/

__
R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see
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] annotate

2023-10-05 Thread Rui Barradas

Às 20:34 de 04/10/2023, Subia Thomas OI-US-LIV5 escreveu:

Colleagues,

I wish to create y-data labels which meet a criterion.

Here is my reproducible code.
library(dplyr)
library(ggplot2)
library(cowplot)

above_92 <- filter(faithful,waiting>92)

ggplot(faithful,aes(x=eruptions,y=waiting))+
   geom_point(shape=21,size=3,fill="orange")+
   theme_cowplot()+
   geom_hline(yintercept = 92)+
   
annotate(geom="text",x=above_92$eruptions,y=above_92$waiting+2,label=above_92$waiting)

A bit of trial and error is required to figure out what number to add or 
subtract to above_92$waiting.

Is there a more efficient way to do this?


Thomas Subia
Lean Six Sigma Senior Practitioner

DRÄXLMAIER Group
DAA Draexlmaier Automotive of America LLC

mailto:thomas.su...@draexlmaier.com
http://www.draexlmaier.com

"Nous croyons en Dieu.
Tous les autres doivent apporter des données.
Edward Deming


Public: All rights reserved. Distribution to third parties allowed.

__
R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see
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.

Hdello,

Yes, there is an automatic way of doing this.
Use a new data set in geom_text or annotate. Below I use geom_text.
Then vjust will take care of the labels placement.




library(dplyr)
library(ggplot2)
library(cowplot)

above_92 <- filter(faithful, waiting > 92)

ggplot(faithful, aes(x = eruptions, y = waiting)) +
  geom_point(shape=21,size=3,fill="orange") +
  geom_hline(yintercept = 92) +
  # use a new data argument here
  geom_text(
data = above_92,
mapping = aes(x = eruptions, y = waiting, label = waiting),
vjust = -1
  ) +
  theme_cowplot()




Hope this helps,

Rui Barradas


--
Este e-mail foi analisado pelo software antivírus AVG para verificar a presença 
de vírus.
www.avg.com

__
R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see
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] annotate

2023-10-05 Thread Eric Berger
Another approach (still seems to require experimentation to get the value
'2') would be to replace the annotate() with

geom_text(data=above_92, aes(x=eruptions,y=waiting, label=waiting),
nudge_y=2)

At least this makes clear the reason for the magic number '2' in the code.

For details see
?geom_text


On Thu, Oct 5, 2023 at 10:38 AM Subia Thomas OI-US-LIV5 <
thomas.su...@draexlmaier.com> wrote:

> Colleagues,
>
> I wish to create y-data labels which meet a criterion.
>
> Here is my reproducible code.
> library(dplyr)
> library(ggplot2)
> library(cowplot)
>
> above_92 <- filter(faithful,waiting>92)
>
> ggplot(faithful,aes(x=eruptions,y=waiting))+
>   geom_point(shape=21,size=3,fill="orange")+
>   theme_cowplot()+
>   geom_hline(yintercept = 92)+
>
> annotate(geom="text",x=above_92$eruptions,y=above_92$waiting+2,label=above_92$waiting)
>
> A bit of trial and error is required to figure out what number to add or
> subtract to above_92$waiting.
>
> Is there a more efficient way to do this?
>
>
> Thomas Subia
> Lean Six Sigma Senior Practitioner
>
> DRÄXLMAIER Group
> DAA Draexlmaier Automotive of America LLC
>
> mailto:thomas.su...@draexlmaier.com
> http://www.draexlmaier.com
>
> "Nous croyons en Dieu.
> Tous les autres doivent apporter des données.
> Edward Deming
>
>
> Public: All rights reserved. Distribution to third parties allowed.
>
> __
> R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see
> 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@r-project.org mailing list -- To UNSUBSCRIBE and more, see
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] annotate

2023-10-05 Thread Subia Thomas OI-US-LIV5
Colleagues,

I wish to create y-data labels which meet a criterion.

Here is my reproducible code.
library(dplyr)
library(ggplot2)
library(cowplot)

above_92 <- filter(faithful,waiting>92)

ggplot(faithful,aes(x=eruptions,y=waiting))+
  geom_point(shape=21,size=3,fill="orange")+
  theme_cowplot()+
  geom_hline(yintercept = 92)+
  
annotate(geom="text",x=above_92$eruptions,y=above_92$waiting+2,label=above_92$waiting)

A bit of trial and error is required to figure out what number to add or 
subtract to above_92$waiting.

Is there a more efficient way to do this?


Thomas Subia
Lean Six Sigma Senior Practitioner

DRÄXLMAIER Group
DAA Draexlmaier Automotive of America LLC

mailto:thomas.su...@draexlmaier.com
http://www.draexlmaier.com

"Nous croyons en Dieu.
Tous les autres doivent apporter des données.
Edward Deming


Public: All rights reserved. Distribution to third parties allowed.

__
R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see
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] Annotate question

2020-02-19 Thread Rui Barradas

Hello,

If groups are factors, pass the level you want to annotate.
This works, note the 'x' value:

ggplot(iris, aes(Species, Petal.Length)) +
  geom_boxplot() +
  annotate(geom = "text", x = "versicolor", y = 6, label = "16 u")


Hope this helps,

Rui Barradas


Às 20:26 de 19/02/20, Thomas Subia escreveu:

Colleagues,

To add an annotation using ggplot, I've used annotate("text",x=17,y=2130,label="16 
u").

However, this does not work when trying to annotate box plots by groups since 
groups are factors.

Any advice would be appreciated.

Thomas Subia
ASQ CQE

IMG Companies
225 Mountain Vista Parkway
Livermore, CA 94551
T. (925) 273-1106
F. (925) 273-
E. tsu...@imgprecision.com


Precision Manufacturing for Emerging Technologies
imgprecision.com

The contents of this message, together with any attachments, are intended only 
for the use of the individual or entity to which they are addressed and may 
contain information that is legally privileged, confidential and exempt from 
disclosure. If you are not the intended recipient, you are hereby notified that 
any dissemination, distribution, or copying of this message, or any attachment, 
is strictly prohibited. If you have received this message in error, please 
notify the original sender or IMG Companies, LLC at Tel: 925-273-1100 
immediately by telephone or by return E-mail and delete this message, along 
with any attachments, from your computer. Thank you.

__
R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see
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@r-project.org mailing list -- To UNSUBSCRIBE and more, see
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] Annotate question

2020-02-19 Thread Stefan Schreiber
Since factor levels (groups) are coded by integers, you can use 1, 2, 3
etc. as your x values. If you want to annotate in between you can simply
pick values in between 1, 2, 3, etc.


On Wed, Feb 19, 2020, 13:26 Thomas Subia,  wrote:

> Colleagues,
>
> To add an annotation using ggplot, I've used
> annotate("text",x=17,y=2130,label="16 u").
>
> However, this does not work when trying to annotate box plots by groups
> since groups are factors.
>
> Any advice would be appreciated.
>
> Thomas Subia
> ASQ CQE
>
> IMG Companies
> 225 Mountain Vista Parkway
> Livermore, CA 94551
> T. (925) 273-1106
> F. (925) 273-
> E. tsu...@imgprecision.com
>
>
> Precision Manufacturing for Emerging Technologies
> imgprecision.com
>
> The contents of this message, together with any attachments, are intended
> only for the use of the individual or entity to which they are addressed
> and may contain information that is legally privileged, confidential and
> exempt from disclosure. If you are not the intended recipient, you are
> hereby notified that any dissemination, distribution, or copying of this
> message, or any attachment, is strictly prohibited. If you have received
> this message in error, please notify the original sender or IMG Companies,
> LLC at Tel: 925-273-1100 immediately by telephone or by return E-mail and
> delete this message, along with any attachments, from your computer. Thank
> you.
>
> __
> R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see
> 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@r-project.org mailing list -- To UNSUBSCRIBE and more, see
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] Annotate question

2020-02-19 Thread Thomas Subia
Colleagues,

To add an annotation using ggplot, I've used 
annotate("text",x=17,y=2130,label="16 u").

However, this does not work when trying to annotate box plots by groups since 
groups are factors.

Any advice would be appreciated.

Thomas Subia 
ASQ CQE

IMG Companies 
225 Mountain Vista Parkway
Livermore, CA 94551
T. (925) 273-1106
F. (925) 273-
E. tsu...@imgprecision.com


Precision Manufacturing for Emerging Technologies
imgprecision.com 

The contents of this message, together with any attachments, are intended only 
for the use of the individual or entity to which they are addressed and may 
contain information that is legally privileged, confidential and exempt from 
disclosure. If you are not the intended recipient, you are hereby notified that 
any dissemination, distribution, or copying of this message, or any attachment, 
is strictly prohibited. If you have received this message in error, please 
notify the original sender or IMG Companies, LLC at Tel: 925-273-1100 
immediately by telephone or by return E-mail and delete this message, along 
with any attachments, from your computer. Thank you.

__
R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see
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] Annotate a segmented linear regression plot

2012-10-02 Thread Ben Harrison
On 28 September 2012 16:38, David Winsemius dwinsem...@comcast.net wrote:

 ?text  # should be fairly clear.

Thank you. I was stupid to ask such a trivial question along with a
not-so-trivial one. The second part of the question was probably more
important: is there a way to obtain the location of segments produced
by the segmented package, so that I can annotate them easily?

I have since asked this question of Vito, the package's author. Here
is his response:

#
dear Ben,
here a possible solution,

o is the segmented fit

  r-o$rangeZ[,1]
  est.psi-o$psi[,2]
  v-sort(c(r, est.psi))
  xCoord-rowMeans(cbind(v[-length(v)], v[-1]))

  Z-o$model[,o$nameUV$Z]

  id-sapply(xCoord, function(x)which.min(abs(x-Z)))
  yCoord-broken.line(o)[id]

  plot(o, col=2:4, res=T)
  text(xCoord, yCoord, labels=formatC(slope(o)[[1]][,1], digits=2),
pos=4, cex=1.3)

Play with pos, cex and digits to modify the appearance of the labels.

vito
#

 Please learn to post in plain text.

I hope this is better.

Ben.

__
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] Annotate a segmented linear regression plot

2012-10-02 Thread David Winsemius

On Oct 2, 2012, at 3:38 PM, Ben Harrison wrote:

 On 28 September 2012 16:38, David Winsemius dwinsem...@comcast.net wrote:
 
 ?text  # should be fairly clear.
 
 Thank you. I was stupid to ask such a trivial question along with a
 not-so-trivial one. The second part of the question was probably more
 important: is there a way to obtain the location of segments produced
 by the segmented package, so that I can annotate them easily?

I guess it depends on what you mean by the location of segments. It's easy 
enough to retrun the x-values for the knots:

o$psi[ , Est.]

I do not see a `predicted.segmented` function, so might need to construct 
separate lm.predict estimates for values between the pairs of x-values if you 
meant you wanted the y-values for the knots.

-- 
David.

 
 I have since asked this question of Vito, the package's author. Here
 is his response:
 
 #
 dear Ben,
 here a possible solution,
 
 o is the segmented fit
 
  r-o$rangeZ[,1]
  est.psi-o$psi[,2]
  v-sort(c(r, est.psi))
  xCoord-rowMeans(cbind(v[-length(v)], v[-1]))
 
  Z-o$model[,o$nameUV$Z]
 
  id-sapply(xCoord, function(x)which.min(abs(x-Z)))
  yCoord-broken.line(o)[id]
 
  plot(o, col=2:4, res=T)
  text(xCoord, yCoord, labels=formatC(slope(o)[[1]][,1], digits=2),
 pos=4, cex=1.3)
 
 Play with pos, cex and digits to modify the appearance of the labels.
 
 vito
 #
 
 Please learn to post in plain text.
 
 I hope this is better.
 
 Ben.

David Winsemius, MD
Alameda, CA, USA

__
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] Annotate a segmented linear regression plot

2012-09-28 Thread David Winsemius

On Sep 27, 2012, at 9:07 PM, Ben Harrison wrote:

 Hello,
 
 I have produced some segmented regressions with the segmented package by
 Viggo Mutteo. I have some example data and code below. I want to annotate
 the individual segments with the slope parameter (actually it would be
 nicer to annotate with 1000*slope and add some small amount of text as
 well). How can I do it? Reading the docs for segmented I can access all of
 the slope parameters via a named vector of the coefficients. How can I
 access the slope segments or locations? I have never tried to annotate an R
 plot before, so I don't even know how to 'pin' a bit of text to an x,y
 location on a plot.
 

?text  # should be fairly clear.


 dput(bullard)
 structure(list(Rt = c(14.4477, 23.6752, 26.723, 33.8508, 37.9628,
 47.0804, 49.7232, 54.6395, 59.9251, 64.7518, 81.1629, 85.7209,
 88.0334, 98.366, 102.6563, 105.6953, 134.8691, 137.3795, 155.0056,
 158.6707, 162.0671, 206.7413, 248.701, 255.9407, 265.5201, 283.1462,
 288.8939, 299.8356, 311.0788, 323.2355, 366.9049, 379.3662, 384.3869,
 392.3246, 436.0853, 439.1246, 454.6023, 458.6247, 464.1744, 479.9764,
 486.5171, 489.5564, 507.5925, 524.7894, 544.0806, 558.7642, 562.4293,
 577.9268, 650.8613, 658.6664, 669.6996, 692.7172, 694.6993),
Tem = c(14.6189, 15.2877, 15.3106, 15.3536, 15.3665, 15.3764,
15.3928, 15.4182, 15.4671, 15.528, 15.5921, 15.7066, 15.7806,
15.8747, 16.0244, 16.146, 16.481, 16.6098, 16.8581, 17.0339,
17.2242, 17.8379, 19.2747, 19.7184, 19.9621, 20.0953, 20.4838,
20.578, 20.774, 21.0112, 23.01, 23.3897, 24.1697, 24.4176,
27.0874, 27.3597, 28.0178, 28.4026, 28.909, 29.7406, 30.532,
30.8734, 32.216, 32.8198, 34.0339, 34.7553, 35.2611, 35.8303,
41.1202, 41.5027, 42.0578, 42.6597, 42.656)), .Names = c(Rt,
 Tem), class = data.frame, row.names = c(NA, -53L))
 
 library(segmented)
 
 out.lm - lm(Tem ~ Rt, data=bullard)
 
 o-segmented(out.lm, seg.Z=~Rt, psi=NA, control=seg.control(display=FALSE,
 K=2))
 
 plot(o, lwd=1,col=2:6, main='Plot title')
 points(bullard)
 abline(out.lm, col=red, lwd=2)
 
 Ben.
 
   [[alternative HTML version deleted]]

Please learn to post in plain text.

--

David Winsemius, MD
Alameda, CA, USA

__
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] Annotate a segmented linear regression plot

2012-09-27 Thread Ben Harrison
Hello,

I have produced some segmented regressions with the segmented package by
Viggo Mutteo. I have some example data and code below. I want to annotate
the individual segments with the slope parameter (actually it would be
nicer to annotate with 1000*slope and add some small amount of text as
well). How can I do it? Reading the docs for segmented I can access all of
the slope parameters via a named vector of the coefficients. How can I
access the slope segments or locations? I have never tried to annotate an R
plot before, so I don't even know how to 'pin' a bit of text to an x,y
location on a plot.

 dput(bullard)
structure(list(Rt = c(14.4477, 23.6752, 26.723, 33.8508, 37.9628,
47.0804, 49.7232, 54.6395, 59.9251, 64.7518, 81.1629, 85.7209,
88.0334, 98.366, 102.6563, 105.6953, 134.8691, 137.3795, 155.0056,
158.6707, 162.0671, 206.7413, 248.701, 255.9407, 265.5201, 283.1462,
288.8939, 299.8356, 311.0788, 323.2355, 366.9049, 379.3662, 384.3869,
392.3246, 436.0853, 439.1246, 454.6023, 458.6247, 464.1744, 479.9764,
486.5171, 489.5564, 507.5925, 524.7894, 544.0806, 558.7642, 562.4293,
577.9268, 650.8613, 658.6664, 669.6996, 692.7172, 694.6993),
Tem = c(14.6189, 15.2877, 15.3106, 15.3536, 15.3665, 15.3764,
15.3928, 15.4182, 15.4671, 15.528, 15.5921, 15.7066, 15.7806,
15.8747, 16.0244, 16.146, 16.481, 16.6098, 16.8581, 17.0339,
17.2242, 17.8379, 19.2747, 19.7184, 19.9621, 20.0953, 20.4838,
20.578, 20.774, 21.0112, 23.01, 23.3897, 24.1697, 24.4176,
27.0874, 27.3597, 28.0178, 28.4026, 28.909, 29.7406, 30.532,
30.8734, 32.216, 32.8198, 34.0339, 34.7553, 35.2611, 35.8303,
41.1202, 41.5027, 42.0578, 42.6597, 42.656)), .Names = c(Rt,
Tem), class = data.frame, row.names = c(NA, -53L))

library(segmented)

out.lm - lm(Tem ~ Rt, data=bullard)

o-segmented(out.lm, seg.Z=~Rt, psi=NA, control=seg.control(display=FALSE,
K=2))

plot(o, lwd=1,col=2:6, main='Plot title')
points(bullard)
abline(out.lm, col=red, lwd=2)

Ben.

[[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] Annotate forest plot 'forest.rma()' for meta-analysis with metafor package

2012-07-25 Thread Viechtbauer Wolfgang (STAT)
Just replace the fixed y coordinate values in the text() calls with something 
that will change appropriately with the number of studies/effects included in 
the plot. For example:

text(c(-9.5,-8,-6,-4.5), res$k+2, c(TB+, TB-, TB+, TB-))
text(c(-8.75,-5.25), res$k+3, c(Vaccinated, Control))
text(-16,res$k+2, Author(s) and Year, pos=4)
text(6,  res$k+2, Relative Risk [95% CI], pos=2)

should do it.

Best,

Wolfgang

--   
Wolfgang Viechtbauer, Ph.D., Statistician   
Department of Psychiatry and Psychology   
School for Mental Health and Neuroscience   
Faculty of Health, Medicine, and Life Sciences   
Maastricht University, P.O. Box 616 (VIJV1)   
6200 MD Maastricht, The Netherlands   
+31 (43) 388-4170 | http://www.wvbauer.com   

 -Original Message-
 From: r-help-boun...@r-project.org [mailto:r-help-boun...@r-project.org]
 On Behalf Of Jokel Meyer
 Sent: Tuesday, July 24, 2012 16:16
 To: r-help@r-project.org
 Subject: [R] Annotate forest plot 'forest.rma()' for meta-analysis with
 metafor package
 
 Dear R-experts,
 
 The forest.rma() function from the metafor package creates nice forest
 plots for presenting the results of a meta-analysis. These plots can be
 annotated for e.g. giving names to the columns. E.g. as in the
 documentation of the package:
 
 data(dat.bcg)
 
 ### meta-analysis of the log relative risks using a random-effects model
 res - rma(ai=tpos, bi=tneg, ci=cpos, di=cneg, data=dat.bcg, measure=RR,
slab=paste(author, year, sep=, ), method=REML)
 
forest(res, slab=paste(dat.bcg$author, dat.bcg$year, sep=, ),
xlim=c(-16, 6), at=log(c(.05, .25, 1, 4)), atransf=exp,
ilab=cbind(dat.bcg$tpos, dat.bcg$tneg, dat.bcg$cpos, dat.bcg$cneg),
ilab.xpos=c(-9.5,-8,-6,-4.5), cex=.75)
 op - par(cex=.75, font=2)
 text(c(-9.5,-8,-6,-4.5), 15, c(TB+, TB-, TB+, TB-))
 text(c(-8.75,-5.25), 16, c(Vaccinated, Control))
 text(-16,15, Author(s) and Year, pos=4)
 text(6,  15, Relative Risk [95% CI], pos=2)
 par(op)
 
 
 However the column names have to be re-positioned everytime the number of
 included studies in the meta-analysis changes.
 E.g.:
 
 dat.bcg - dat.bcg[1:12,]
 
 ### meta-analysis of the log relative risks using a random-effects model
 res - rma(ai=tpos, bi=tneg, ci=cpos, di=cneg, data=dat.bcg, measure=RR,
slab=paste(author, year, sep=, ), method=REML)
 
 forest(res, slab=paste(dat.bcg$author, dat.bcg$year, sep=, ),
xlim=c(-16, 6), at=log(c(.05, .25, 1, 4)), atransf=exp,
ilab=cbind(dat.bcg$tpos, dat.bcg$tneg, dat.bcg$cpos, dat.bcg$cneg),
ilab.xpos=c(-9.5,-8,-6,-4.5), cex=.75)
 op - par(cex=.75, font=2)
 text(c(-9.5,-8,-6,-4.5), 15, c(TB+, TB-, TB+, TB-))
 text(c(-8.75,-5.25), 16, c(Vaccinated, Control))
 text(-16,15, Author(s) and Year, pos=4)
 text(6,  15, Relative Risk [95% CI], pos=2)
 par(op)
 
 Is there a way to define the colum names' position relatively to the plot
 so they would be adequately positioned no matter what is the number of
 studies included in the plot?
 
 
 Many thanks for your help!,
 Jokel

__
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] Annotate forest plot 'forest.rma()' for meta-analysis with metafor package

2012-07-24 Thread Jokel Meyer
Dear R-experts,

The forest.rma() function from the metafor package creates nice forest
plots for presenting the results of a meta-analysis. These plots can be
annotated for e.g. giving names to the columns. E.g. as in the
documentation of the package:

data(dat.bcg)

### meta-analysis of the log relative risks using a random-effects model
res - rma(ai=tpos, bi=tneg, ci=cpos, di=cneg, data=dat.bcg, measure=RR,
   slab=paste(author, year, sep=, ), method=REML)

   forest(res, slab=paste(dat.bcg$author, dat.bcg$year, sep=, ),
   xlim=c(-16, 6), at=log(c(.05, .25, 1, 4)), atransf=exp,
   ilab=cbind(dat.bcg$tpos, dat.bcg$tneg, dat.bcg$cpos, dat.bcg$cneg),
   ilab.xpos=c(-9.5,-8,-6,-4.5), cex=.75)
op - par(cex=.75, font=2)
text(c(-9.5,-8,-6,-4.5), 15, c(TB+, TB-, TB+, TB-))
text(c(-8.75,-5.25), 16, c(Vaccinated, Control))
text(-16,15, Author(s) and Year, pos=4)
text(6,  15, Relative Risk [95% CI], pos=2)
par(op)


However the column names have to be re-positioned everytime the number of
included studies in the meta-analysis changes.
E.g.:

dat.bcg - dat.bcg[1:12,]

### meta-analysis of the log relative risks using a random-effects model
res - rma(ai=tpos, bi=tneg, ci=cpos, di=cneg, data=dat.bcg, measure=RR,
   slab=paste(author, year, sep=, ), method=REML)

forest(res, slab=paste(dat.bcg$author, dat.bcg$year, sep=, ),
   xlim=c(-16, 6), at=log(c(.05, .25, 1, 4)), atransf=exp,
   ilab=cbind(dat.bcg$tpos, dat.bcg$tneg, dat.bcg$cpos, dat.bcg$cneg),
   ilab.xpos=c(-9.5,-8,-6,-4.5), cex=.75)
op - par(cex=.75, font=2)
text(c(-9.5,-8,-6,-4.5), 15, c(TB+, TB-, TB+, TB-))
text(c(-8.75,-5.25), 16, c(Vaccinated, Control))
text(-16,15, Author(s) and Year, pos=4)
text(6,  15, Relative Risk [95% CI], pos=2)
par(op)

Is there a way to define the colum names' position relatively to the plot
so they would be adequately positioned no matter what is the number of
studies included in the plot?


Many thanks for your help!,
Jokel

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


[R] annotate histogram

2011-11-01 Thread Wendy
Hi all,

I want to make a histogram like the one show 
http://nar.oxfordjournals.org/content/39/suppl_1/D1011/F1.expansion.html
here , but I did not figure out how to add the red marks at the bottom of
the bars. Could anybody help? Thank you very much

--
View this message in context: 
http://r.789695.n4.nabble.com/annotate-histogram-tp3963960p3963960.html
Sent from the R help mailing list archive at Nabble.com.

__
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] annotate histogram

2011-11-01 Thread Carlos Ortega
Hi,

You can use function segments() to draw them.


Regards,
Carlos Ortega
www.qualityexcellence.es

2011/11/1 Wendy wendy2.q...@gmail.com

 Hi all,

 I want to make a histogram like the one show
 http://nar.oxfordjournals.org/content/39/suppl_1/D1011/F1.expansion.html
 here , but I did not figure out how to add the red marks at the bottom of
 the bars. Could anybody help? Thank you very much

 --
 View this message in context:
 http://r.789695.n4.nabble.com/annotate-histogram-tp3963960p3963960.html
 Sent from the R help mailing list archive at Nabble.com.

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


[[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] annotate histogram

2011-11-01 Thread Tom Fletcher
See rug() and use col=2 to get red. So, as an example ...

x - rchisq(100, df=2)
hist(x)
abline(v=median(x), lty=2)
rug(x, col=2)

TF

-Original Message-
From: r-help-boun...@r-project.org [mailto:r-help-boun...@r-project.org] On 
Behalf Of Wendy
Sent: Tuesday, November 01, 2011 10:22 AM
To: r-help@r-project.org
Subject: [R] annotate histogram

Hi all,

I want to make a histogram like the one show 
http://nar.oxfordjournals.org/content/39/suppl_1/D1011/F1.expansion.html
here , but I did not figure out how to add the red marks at the bottom of the 
bars. Could anybody help? Thank you very much

--
View this message in context: 
http://r.789695.n4.nabble.com/annotate-histogram-tp3963960p3963960.html
Sent from the R help mailing list archive at Nabble.com.

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