[R-meta] R-meta] add comma to numbers in forest plot from metaprop objet

Dr. Gerta Rücker gert@@ruecker @end|ng |rom un|k||n|k-|re|burg@de
Fri Dec 1 17:43:52 CET 2023


Dear Sofia,

Try this code:

library(meta)
events <- c(12000, 5000, 800, 30000)  # Example event counts
n <- c(50000, 10000, 5000, 40000)  # Example total sample sizes

formatted_events <- format(events, big.mark=",")
formatted_n <- format(n, big.mark=",")

meta_result <- metaprop(event = events, n = n)
meta_result$formatted_events <- formatted_events
meta_result$formatted_n <- formatted_n

forest(meta_result, 
       leftcols = c("studlab", "formatted_events", "formatted_n"),
       leftlabs = c("Study", "Events","Total"))

Remarks: 
- The formatted numbers should be list elements of the metaprop object, not of the data. 
- It makes sense to format also the sample sizes (n) in the same way.
- It also makes sense to format *all* numbers equally, also those that are smaller than 10000.
- It does not make sense to format the numbers as characters (as you did), because then don't become right-justified.

Best,
Gerta


UNIVERSITÄTSKLINIKUM FREIBURG
Institute for Medical Biometry and Statistics

Dr. Gerta Rücker
Guest Scientist

Stefan-Meier-Straße 26 · 79104 Freiburg
gerta.ruecker using uniklinik-freiburg.de

https://www.uniklinik-freiburg.de/imbi-en/employees.html?imbiuser=ruecker

-----Ursprüngliche Nachricht-----
Von: Zoukal Sofia via R-sig-meta-analysis <r-sig-meta-analysis using r-project.org> 
Gesendet: Freitag, 1. Dezember 2023 12:44
An: r-sig-meta-analysis using r-project.org
Cc: Zoukal Sofia <sofi.cap using gmail.com>
Betreff: [R-meta] R-meta] add comma to numbers in forest plot from metaprop objet

*Hi,
**I need to modify the numbers in the columns of a forest plot made
from a metaprop object.*

*Please how can **I** add commas for numbers w**ith 5 or more digits
in **column** of event and total to appear in the forest plot?*

*#there is my data:*

events <- c(12000, 5000, 800, 30000)  # Example event counts

n <- c(50000, 10000, 5000, 40000)  # Example total sample sizes
data <- data.frame( events = events, n = n)

# Format event counts with commas for numbers with 5 or more digits
formatted_events <- ifelse(events >= 10000, format(events,
big.mark=","), as.character(events))
data$events_formatted <- formatIfNeeded(data$events)
print(data)

# Run meta-analysis with the modified dataset
meta_result <- metaprop(event = formatted_events, n = n)

# Plot the forest plot for the meta-analysis with formatted data

forest(meta_result)


Unfortunatlly, it does not work: "Error: Non-numeric value for argument 'event'"

help me please!

Best

ᐧ

	[[alternative HTML version deleted]]

_______________________________________________
R-sig-meta-analysis mailing list @ R-sig-meta-analysis using r-project.org
To manage your subscription to this mailing list, go to:
https://stat.ethz.ch/mailman/listinfo/r-sig-meta-analysis


More information about the R-sig-meta-analysis mailing list