*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 ?
[R-meta] R-meta] add comma to numbers in forest plot from metaprop objet
5 messages · Zoukal Sofia, Dr. Gerta Rücker, Guido Schwarzer
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 at 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 at r-project.org>
Gesendet: Freitag, 1. Dezember 2023 12:44
An: r-sig-meta-analysis at r-project.org
Cc: Zoukal Sofia <sofi.cap at 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
?
_______________________________________________
R-sig-meta-analysis mailing list @ R-sig-meta-analysis at r-project.org
To manage your subscription to this mailing list, go to:
https://stat.ethz.ch/mailman/listinfo/r-sig-meta-analysis
2 days later
Sofia,
You can set argument 'big.mark' in settings.meta() which is considered in printouts and forest plots.
events <- c(12000, 5000, 800, 30000)
n <- c(50000, 10000, 5000, 40000)
library("meta")
settings.meta(big.mark = ",")
m <- metaprop(events, n)
forest(m)
Best,
Guido
1 day later
Hi, Thank you so much for your help! Best ? Le lun. 4 d?c. 2023 ? 13:24, Dr. Guido Schwarzer < guido.schwarzer at uniklinik-freiburg.de> a ?crit :
Sofia,
You can set argument 'big.mark' in settings.meta() which is considered in
printouts and forest plots.
events <- c(12000, 5000, 800, 30000)
n <- c(50000, 10000, 5000, 40000)
library("meta")
settings.meta(big.mark = ",")
m <- metaprop(events, n)
forest(m)
Best,
Guido
Hi, Thank you so much for your help! Best ? Le lun. 4 d?c. 2023 ? 13:24, Dr. Guido Schwarzer < guido.schwarzer at uniklinik-freiburg.de> a ?crit :
Sofia,
You can set argument 'big.mark' in settings.meta() which is considered in
printouts and forest plots.
events <- c(12000, 5000, 800, 30000)
n <- c(50000, 10000, 5000, 40000)
library("meta")
settings.meta(big.mark = ",")
m <- metaprop(events, n)
forest(m)
Best,
Guido