R does not put the chart in pdf
1
0
Entering edit mode
5.0 years ago
Sib ▴ 60

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 • 6.1k views
ADD COMMENT
3
Entering edit mode
5.0 years ago

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 COMMENT
0
Entering edit mode

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 REPLY
2
Entering edit mode

dev.off(), not dev.off.

ADD REPLY
0
Entering edit mode

thank you very much.

ADD REPLY
0
Entering edit mode

It worked. thanks.

ADD REPLY
0
Entering edit mode

shouldn't that be:

graphics.off()

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

?

ADD REPLY
0
Entering edit mode

Can work, too.

ADD REPLY

Login before adding your answer.

Traffic: 2728 users visited in the last hour
Help About
FAQ
Access RSS
API
Stats

Use of this site constitutes acceptance of our User Agreement and Privacy Policy.

Powered by the version 2.3.6