Question: R does not put the chart in pdf
0
gravatar for Sib
5 weeks 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 • 129 views
ADD COMMENTlink modified 5 weeks ago by Kevin Blighe53k • written 5 weeks ago by Sib20
3
gravatar for Kevin Blighe
5 weeks ago by
Kevin Blighe53k
Kevin Blighe53k 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 5 weeks ago • written 5 weeks ago by Kevin Blighe53k

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 5 weeks ago • written 5 weeks ago by Sib20
2

dev.off(), not dev.off.

ADD REPLYlink written 5 weeks ago by Devon Ryan93k

thank you very much.

ADD REPLYlink written 5 weeks ago by Sib20

It worked. thanks.

ADD REPLYlink written 5 weeks ago by Sib20

shouldn't that be:

graphics.off()

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

?

ADD REPLYlink modified 5 weeks ago • written 5 weeks ago by cpad011212k

Can work, too.

ADD REPLYlink written 5 weeks ago by Kevin Blighe53k
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: 1119 users visited in the last hour