Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
211 views
in Technique[技术] by (71.8m points)

r - How to save a plot at high resolution and then show it in the RMarkdown knitted file

Tried the following code:

png(filename = "forestv8aall.png",
    width = 2000,
    height = 1750,
    res = 135)

forest(allexpcollapsed,
       alim =c(-2, 4),
       xlim =c(-4, 5),
       ilab = totalexp$N.sample.size..post.attrition., 
       ilab.xpos = -2,
       xlab = "Omission-bias effect",
       cex = .8)

# Add headlines to the forest
op <- par(font=4)
text(-4,
     allexpcollapsed$k + 2,
     "Author(s), Year, and Study #",
     pos = 4,
     cex = .8)
text(5,
     allexpcollapsed$k + 2,
     "Observed [95% CI]",
     pos = 2,
     cex = .8)
text(-2,
     allexpcollapsed$k + 2,
     "Sample size",
     cex=.8)
par(op)
dev.off()

The below is shown in the RMD Knitted file:

## png 
##   2

I was able to see the output png file in the same folder though.

How to fix this so that the high-resolution plot is also shown in the RMD knitted word file? Thanks in advance!

question from:https://stackoverflow.com/questions/65650071/how-to-save-a-plot-at-high-resolution-and-then-show-it-in-the-rmarkdown-knitted

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

Using RStudio preferably (makes all of it much easier), create an Rmd file and put your R code in an R chunk. To display the image, simply use this syntax (this would be outside the R chunk):

![Optional replacement text](forestv8aall.png)

Then press on the "knit" button and voilà!


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

1.4m articles

1.4m replys

5 comments

57.0k users

...