Question: R does not put the chart in pdf
0
gravatar for Sib
11 months ago by
Sib20
Sib20 wrote:

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 • 501 views
ADD COMMENTlink modified 11 months ago by Kevin Blighe67k • written 11 months ago by Sib20
3
gravatar for Kevin Blighe
11 months ago by
Kevin Blighe67k
Republic of Ireland
Kevin Blighe67k wrote:

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

ADD COMMENTlink modified 11 months ago • written 11 months ago by Kevin Blighe67k

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>
ADD REPLYlink modified 11 months ago • written 11 months ago by Sib20
2

dev.off(), not dev.off.

ADD REPLYlink written 11 months ago by Devon Ryan97k

thank you very much.

ADD REPLYlink written 11 months ago by Sib20

It worked. thanks.

ADD REPLYlink written 11 months ago by Sib20

shouldn't that be:

graphics.off()

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

?

ADD REPLYlink modified 11 months ago • written 11 months ago by cpad011214k

Can work, too.

ADD REPLYlink written 11 months ago by Kevin Blighe67k
Please log in to add an answer.

Help
Access

Use of this site constitutes acceptance of our User Agreement and Privacy Policy.
Powered by Biostar version 2.3.0
Traffic: 1889 users visited in the last hour