Reputation: 2443
I've read all posts relevant to this problem.But the truth is: if you have lots of variables to plot,this problem still occur.
My laptop resolution is 1080p, I open rstudio and run below script:
a<-iris[,1:4]
> a<-t(a)
> a<-as.data.frame(a)
> pairs(a)
Error in plot.new() : figure margins too large
I have tried all the solution in this site from similar questions, none is workable.
I really need this plot but cannot get it.How to solve this problem?
Upvotes: 2
Views: 19770
Reputation: 67
RStudio simply cannot show very large plots. If you have a grouping variable, specify the rows for each category/factor and plot again; this becomes a smaller plot:
EX: If you have a dataframe with 100 rows for 2 groups x and y as in the column 'groups', and 20 columns as variables to plot for each group, to get the plots for all columns for the x (corresponding to rows 1:50):
library(tidyverse)
df[1:50,] %>%
keep(is.numeric) %>%
gather() %>%
ggplot(aes(value)) +
facet_wrap(~ key, scales = "free") +
geom_histogram()
hope this helps!
Upvotes: 0
Reputation: 9
The problem seems to be caused because the image will not fit into the graphics window as rendered for the global settings. Make sure that your zoom is not set beyond 100 %
Upvotes: 0
Reputation: 226087
The only way I can possibly imagine doing this is (as I think has previously been suggested) sending the output to a PDF file and then using a PDF viewer to look at it. (My answer is very similar to the answer you got to this question, except that I'm using PDF rather than PNG as output ... tried it for PNG as well, seems to work for 2000x2000 pixels ...)
For smaller/reasonable examples, zooming and/or opening an external graphics window with dev.new()
should work ...
a <- iris[,1:4]
a <- t(a)
a <- as.data.frame(a)
pdf(file="tmp.pdf",width=100,height=100)
pairs(a,gap=0,pch=".")
dev.off()
This took about 18 seconds on my laptop and produced a 1.2M PDF file. Here's what the picture looked like when I zoomed all the way out ("fit to window") in my PDF viewer:
If you have 150x150 subplots and want to render each one at 1 cm wide x 1 cm tall (which seems pretty small for viewing any detail), you're either going to need a very high-resolution projector or a large-format (poster) printer. You could scroll around the image with a PDF viewer, but it doesn't seem very practical ...
Upvotes: 2
Reputation: 513
I'll answer in two ways. Firstly, as you're using the iris dataset, are you sure you want a pairs plot of the transpose of a? That would mean comparing the individual flowers, rather than the features (like sepal length etc). Is this what you want instead?
> a <- iris[,1:4]
> pairs(a)
This will give you a 4x4 pairs plot (comparing the flower features). If however, you really do want a pairs plot between observations instead of features, then you're asking for a 150x150 pairs plot! It seems to me that the only way to do that is to generate multiple pairs plots, each one for a subset of those 150 items.
Upvotes: 2