Specify Width and Height of Plot

前端 未结 3 463
感动是毒
感动是毒 2020-12-24 02:44

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?

3条回答
  •  感情败类
    2020-12-24 03:26

    Neither solution works in Jupyter notebooks. 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')
    

提交回复
热议问题