plots were too small while I tried to plot multiple graphics

Description of issue - I used mfrow code to draw a multiple graphics, but the axes were too small and even can't see the pictures clearly. It makes me confused, maybe there is some setting problem but I cannot find it.

Here is my code:

dev.off();
par(mfrow=c(3,1));
hist(disk,xlim=c(-300,250));
hist(inter,xlim=c(-300,250));
hist(halo,xlim=c(-300,250))

System Information:

  • RStudio Edition: (Desktop or Server)
  • RStudio Version: Version 1.2.1335
  • OS Version:
  • R Version:
  • sessionInfo():

Referred here from support.rstudio.com

I think this is most easily fixed by changing the size of the device where the plot appears. You can maximize the plot pane in RStudio by clicking on the larger of the two rectangular icons at the top right corner of the pane. You can also launch a separate graphic device using the windows() function if your OS is Windows or X11() if you are on Linux. That command would be run in the console and look like

windows(width = 12, height = 10)

and you can adjust the width and height as needed.

In addition to the advice from @FJCC about resizing the graphic device, you may also want to consider either rescaling your data, or visualizing the data in a different way. Of course, changing the data or the plot fundamentally changes the way you present the data, but perhaps it will create a more expressive plot. Removing duplicate x-axes and titles could help utilize space.

Without your data, I simulated some data that I think approximately had the same spread as yours. Here is an example I thought might work.

library(ggplot2)
library(dplyr)
data <- data.frame(
  id = 1:10,
  disk = rnorm(100, 0, 100),
  halo = rnorm(100, 0, 100),
  inter = rnorm(100, 0, 100)
)
# Like your original plot
data %>% 
  gather('key', 'value', -id) %>% 
  ggplot(aes(value)) +
  geom_histogram() +
  facet_wrap(~key, nrow = 3)
2 Likes


I've already maximized the plot pane, but the plots still look very narrow. If I drag the left side of the pane, it will only make the graphics longer in x-axes, rather than the right size in both x and y axes. Using windows() is good, but it's really inconvenience to check the plots.

You can change the plot margins so that the top and bottom margins take up less vertical space. Run par("mar") to see the default margins, which are c(5.1,4.1,4.1,2.1) in order c(bottom, left, top, right) (run ?par and scroll down to mar to see the help for this). Reduce the bottom and/or top margins as needed. For example:

# Fake data
set.seed(3)
disk = rnorm(100, 0, 100)
halo = rnorm(100, 0, 100)
inter = rnorm(100, 0, 100)

# Original margins
par(mfrow=c(3,1))
hist(disk,xlim=c(-300,250))
hist(inter,xlim=c(-300,250))
hist(halo,xlim=c(-300,250))  

# Save default margins while setting new margins
old.par = par(mar = c(3, 4, 1, 2))

hist(disk,xlim=c(-300,250))
hist(inter,xlim=c(-300,250))
hist(halo,xlim=c(-300,250)) 

# Reset to default margins
par(old.par)

Sorry, I don't think I have clearly expressed my problem. So I found an example to illustrate it.

The first image below is the normal look of the multiple graphics displayed. The scale of plots all in a suitable size.

However, I tried to use the same code to plot the same graphics using my Rstudio, it showed a different scale of x and y axes(As shown in the second image below). I don't know what's wrong with it and I want to fix it. I've already maximized my plot pane and no matter how I drag the border, I can't get the normal scale of the graph.

How the plot looks results from some combination of the margins and the physical size of the plot pane (or, if you save the plot to PDF or PNG, the physical size of the saved plot). For example, here is the same plot, with the default margins, but with the plot pane sized two different ways:

Or, saving to PDF:

pdf("wide.pdf", 8, 4)
par(mfrow=c(3,1))
hist(disk,xlim=c(-300,250))
hist(inter,xlim=c(-300,250))
hist(halo,xlim=c(-300,250))  
dev.off()

pdf("tall.pdf", 8, 8)
par(mfrow=c(3,1))
hist(disk,xlim=c(-300,250))
hist(inter,xlim=c(-300,250))
hist(halo,xlim=c(-300,250))  
dev.off()

Thanks for your helping. However, I notice that this example can't illustrate my problem clearly, because when I dragged the broder , those plots became normal.
So I found another example.


The first picture is an example in the video, these four pictures are drawn like this.The scales of both x and the y axis of the graphic will be automatically change to the appropriate size as the border of plot pane was dragged.
But, the graphics I drew looks strange(as the second picture show). No matter how I dragged the border, the graphics only be stretched horizontally.

It's hard to be sure what's going on without seeing the full code you're running. One issue I can see (barely) in the picture of your code is par(oma=c(6,0,6,0)). This creates outer top and bottom margins of 6 lines each, which is squishing your plots. That's why there's so much empty white space on the top and bottom.

It will be much easier to help you for this and future problems if you provide copy-and-pasteable code, rather than images. This post summarizes how to provide data and code in ways that make it as easy as possible to help you.

1 Like

This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.