How to resize an R plot in the report generated by compile report (Not in R Markdown)?

huangapple go评论63阅读模式
英文:

How to resize an R plot in the report generated by compile report (Not in R Markdown)?

问题

在R Studio中,有一个选项可以在R Markdown中不编写代码的情况下编译报告。在Mac上的键盘组合是Shift + Command + K。当我在下面的代码中使用它时:

par(mfrow = c(2,1))  

plot(pressure$pressure~pressure$temperature) 
curve((0.168 + 0.007*x)^(20/3), from = 0, to = 400, add = TRUE) 
mtext("Temperature vs. Pressure (Unadjusted)", side = 3, cex = 1.2) 

plot(pressure$pressure^(3/20)~pressure$temperature) 
abline(0.168,0.007) 
mtext("Temperature vs. Pressure (Adjusted)", side = 3, cex = 1.2) 

它会生成类似这样的报告:

How to resize an R plot in the report generated by compile report (Not in R Markdown)?

有没有办法调整报告中的图的大小?例如,如何设置宽度为 800,高度为 1000,就像下面的图片一样?

How to resize an R plot in the report generated by compile report (Not in R Markdown)?

英文:

In R Studio, there is an option to compile a report without writing codes in the R Markdown. The keyboard combination on Mac is Shift + Command + K. When I use it on the following code:

par(mfrow = c(2,1))  

plot(pressure$pressure~pressure$temperature) 
curve((0.168 + 0.007*x)^(20/3), from = 0, to = 400, add = TRUE) 
mtext("Temperature vs. Pressure (Unadjusted)", side = 3, cex = 1.2) 

plot(pressure$pressure^(3/20)~pressure$temperature) 
abline(0.168,0.007) 
mtext("Temperature vs. Pressure (Adjusted)", side = 3, cex = 1.2) 

it gives a report like this:
How to resize an R plot in the report generated by compile report (Not in R Markdown)?

Is there a way to resize the plot in the report? For example, how to set it to width 800, and height 1000 as in the following image?

How to resize an R plot in the report generated by compile report (Not in R Markdown)?

答案1

得分: 1

你可以使用特殊注释(类似于块选项)来设置图的宽度和高度,例如:

#+ fig.height = 10.4, fig.width = 8.3

在你创建绘图的位置上方。请注意,这里图的尺寸始终以英寸为单位(不同于你的示例中的像素),因此你需要从像素转换为英寸。

英文:

You can set the figure width and height using special comments (similar to chunk options) e.g.

#+ fig.height = 10.4, fig.width = 8.3

above where you create the plot. Note that here the figure sizes are always given in inches (not pixels as in your example, so you would need to convert from pixels to inches).

huangapple
  • 本文由 发表于 2023年2月16日 06:48:12
  • 转载请务必保留本文链接:https://go.coder-hub.com/75466142.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定