[英]Specify Width and Height of Plot
I have a panel containing three plots. 我有一个包含三个图的面板。 How can I use
par
to specify the width and height of the main panel so it is always at a fixed size? 如何使用
par
指定主面板的宽度和高度,使其始终保持固定大小?
You do that in the device, eg 你在设备中这样做,例如
x11(width=4, height=6)
and similarly for the file-based ones 类似地,基于文件的
pdf("/tmp/foo.pdf", width=4, height=6)
You can read the physical size via par("cin")
etc but not set it. 您可以通过
par("cin")
等读取物理尺寸,但不能设置它。
I usually set this at the start of my session with windows.options
: 我通常在我的会话开始时使用
windows.options
:
windows.options(width=10, height=10)
# plot away
plot(...)
If you need to reset to "factory settings": 如果您需要重置为“出厂设置”:
dev.off()
windows.options(reset=TRUE)
# more plotting
plot(...)
Neither solution works in Jupyter notebooks . 这两种解决方案都不适用于Jupyter笔记本电脑 。 Here is a general approach that works in any environment:
以下是适用于任何环境的一般方法:
options(repr.plot.width=6, repr.plot.height=4)
Just keep the following function handy: 只需保持以下功能:
set_plot_dimensions <- function(width_choice, height_choice) {
options(repr.plot.width=width_choice, repr.plot.height=height_choice)
}
EXAMPLE 例
Data 数据
x <- c(37.50,46.79,48.30,46.04,43.40,39.25,38.49,49.51,40.38,36.98,40.00,38.49,37.74,47.92,44.53,44.91,44.91,40.00,41.51,47.92,36.98,43.40)
Call function with dimensions, and draw plot: 用尺寸调用函数,绘制图:
set_plot_dimensions(6, 4)
show_distribution(x, 'test vector')
set_plot_dimensions(16, 4)
show_distribution(x, 'test vector')
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.