This is a test version of Biostars. For the public version, visit https://www.biostars.org.
R does not put the chart in pdf

I write these commands in R to drow my chart

pdf("results/boxplot.pdf")
boxplot(x)
dev.off()

but in the "results" folder just an empty pdf with no boxplot is created. And when I open the pdf it says "there was an error opening this document". This file is already open or in use by another application". And this problem also occurs when I want to draw a heatmap. What should I do?

r

1 answer

You probably have another device / output stream open. Run the following and it will work:

dev.off()
dev.off()
dev.off()
dev.off()
dev.off()

pdf("results/boxplot.pdf")
  boxplot(x)
dev.off()

Basically, run dev.off() until it returns an error, then —and only then— regenerate the plot.

By the way, if simply running boxplot(x) does not even generate a graphic, then you have another issue, in which case please show all of your code.

Kevin

Thank you for your answer I ran dev.off() many times but it didn't work. after each dev.off says this:

function (which = dev.cur()) 
{
    if (which == 1) 
        stop("cannot shut down device 1 (the null device)")
    .External(C_devoff, as.integer(which))
    dev.cur()
}
<bytecode: 0x209f8be0>
<environment: namespace:grDevices>

dev.off(), not dev.off.

thank you very much.

It worked. thanks.

shouldn't that be:

graphics.off()

pdf("results/boxplot.pdf")
  boxplot(x)
dev.off()

?

Log in to answer this question.