Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Rmarkdown produces each plot twice #8

Open
caconchon opened this issue Sep 5, 2023 · 1 comment
Open

Rmarkdown produces each plot twice #8

caconchon opened this issue Sep 5, 2023 · 1 comment

Comments

@caconchon
Copy link

Hi,
I've been using the package to plot forestplots (forest_plot() function) and when using it in rmd, the plot is produced twice in the source script. If I use fig.keep='last' in the chunk, it knits with only figure, but the source script keeps producing double plots.
Is there anything else I can try?
issue coveffectsplot

@smouksassi
Copy link
Owner

the code is "printing" an egg::ggarrange(plot,table) it might be related to this
https://stackoverflow.com/questions/71936921/rmarkdown-knitting-produces-each-plot-twice

in the vignettes I save to png then I include in my markdown
png("./coveffectsplot_color.png",width =9.5 ,height = 6,units = "in",res=72)
forest_plot(fpdata...
dev.off()
Color By Parameter Covariate Effects Plot.

another way if you do not want to save to pngs
supress the graphics outputs with return_list = TRUE then print and display as you see fit

fp.0 = R.devices::suppressGraphics (coveffectsplot::forest_plot(fpdata[paramname=="AUC"],
ref_area = c(0.8, 1/0.8),
x_range = c(0.5,2),
xlabel = "Fold Change Relative to Reference",
x_label_text_size= 10,
y_facet_text_angle = 0,
facet_formula = "covname~paramname",
theme_benrich = TRUE,
table_title_size = 15,
table_title = "Median [90% CI]",
interval_legend_text = interval_legend_text,
interval_bsv_text = interval_bsv_text,
legend_position = "none",
strip_placement = "outside",
base_size = 12,
facet_switch = "y",
facet_scales = "free_y",
facet_space = "free",
paramname_shape = FALSE,
table_position = "right",
table_text_size=4,
plot_table_ratio = 3,
show_table_facet_strip = "none",
logxscale = TRUE,
major_x_ticks = c(0.25,0.5,0.8,1,1/0.8,1/0.5,1/0.25),
major_x_labels = c("1/4","1/2","0.8","1","1.25","2","4"),
return_list = TRUE)
)

egg::ggarrange(
fp.0[[1]] ,
fp.0[[2]],
nrow = 1, widths = c(2, 1)
)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants