Closed EOGrady21 closed 5 years ago
I think the problem has to do with resizing and margins (or, at least, some aspect of plot-device geometry). Other packages seem to have similar problems. I have never figured out a way to fix this. My solution is to always redraw the plot, if I resize the plot window.
Of course, what you say is that you are trying to 'export' the plot, but I think this involves resizing within Rstudio.
My suggested solution is simply to put a png()
call before the plot (or a pdf()
or whatever you like) and then a dev.off()
call after the plot.
As for making 'export' work, I don't really know on that, sorry. Someone else in your working group may be more familiar with what Rstudio is doing.
Sorry, not much help ... except that having explicit png()
etc calls is very useful in reproducibility. Otherwise, you may find it difficult to get the same plot on another day! I always write e.g.
if (!interactive()) png(...)
... plot commands
if (!interactive()) dev.off()
because then the .R code works fine interactively, but when you run it non-interactively, it makes the plots. Another approach is to put
externalPlot <- TRUE || !interactive()
at the start of the code, and then to test on that. This way, you can even create the files in an interactive session, just by changing that line.
Thanks for the tip, Dan! This solved my issue.
Cheers!
I'm late, and you've figured it out, but I wanted to echo Dan's caution that the RStudio plot window can behave weirdly compared to the "regular" R plot windows. I often avoid using it for imagep()
plots by using dev.new()
when I'm working interactively.
Also, when we sit down to chat (though I see you are making progress without me ... :P) I can show you some tricks that you can use so that your plots are only saved to files when they are run a certain way, which means that if you are actively working on the code in an R session, you'll see the plots. But when it's done, you run it from outside of the active R session, and then the plots will be saved.
Oh, I should have read the whole thread ... Dan already gave you some of those pointers.
🤷♂️
Short summary of problem
Palette is filling behind imagep() plot
Details (optional)
When exporting plots, the colorbar palette fills ~3/4 of the background of the plot
What you did
missingColor
argument to fill in plot background with unsatisfactory resultsdrawPalette
argument on and offWhat you expected to happen
Plot 1 shows in display window in R studio
but Plot 2 is exported
How urgent is this?
Not urgent!
Output from sessionInfo()