Entering edit mode
mictadlo
▴
10
@mictadlo-10885
Last seen 4.9 years ago
Hi, the following plot get saved as png but it does not show up inside Rstudio.
png("~/sampledata.png")
x <- matrix(rnorm(1000*6,sd=sd),1000,6)
rownames(x) <- paste("Gene",1:1000)
x[1:50,4:6] <- x[1:50,4:6] + 2
## capture par settings, then add space to the right
opar <- par(no.readonly = TRUE)
par(xpd = TRUE, mar = par()$mar + c(0, 0, 0, 5))
## get yer plot on
plotMDS(x, pch = 16, col = c(rep("black",3), rep("red",3)))
legend(par("usr")[2], par("usr")[4], c("Grp1","Grp2"), pch = 16, col = c("black","red"), bty = "n")
## set par back to original
par(opar)
dev.off()
How is is possible to store the plot as png and show it inside Rstudio?
Thank you in advance.
AFAIK you'll need to run the
plotMDS
command outside of thepng() ... dev.off()
structure again to make it visible in RStudio.You mean I have to run it twice?
This has nothing to do with Rstudio. When you plot something in R, the output is captured by a device. If you start with a call to
png
, then you are capturing by the png device so you can generate a plot. If you just run the code, it gets captured by the graphics device and is plotted in a window.You can always capture the plot separately and then replay it for different devices, however.
But do note that the converse (running within
png
, then trying to capture usingrecordPlot
) doesn't work.