When I am working with graphs in R
, I try to output them directly into PDF. For e.g. the code for creating a graph is as follows.
library(ggplot2)
levels_fp = ggplot(data=df_forest_2,
aes(x = levels,y=center, ymin=lower, ymax=upper))+
geom_pointrange(aes(col=levels))+
geom_hline(aes(fill=levels),yintercept =1, linetype=2)+
xlab('Outcomes Evaluated')+ geom_errorbar(aes(ymin=lower, ymax=upper,col=levels),width=0.2,cex=1)+
facet_wrap(~outcome,strip.position="top",nrow=1,scales = "free_x") + theme(
axis.title = element_text(size = 18),
axis.text = element_text(size = 14),
legend.text = element_text(size = 16),
legend.title = element_text(size = 16),
panel.grid.major = element_blank(),
panel.grid.minor = element_blank(),
axis.line = element_line(colour = "black"),
legend.box.background = element_rect(),axis.text.x = element_blank(), strip.text.x = element_text(size = 14)
) + ylab("Odds Ratio")+labs(col="Interventions")
pdf(file="Forest_levels_2.pdf", width=12,height =12 )
levels_fp
dev.off()
The thing I am intrigued about is: suppose I have kept the pdf (which I output from the previous step, namely Forest_levels_2.pdf) open in a PDF viewer. Then, if I run the code again, the file gets output and overwrites the previous PDF, and the output in PDF viewer is also instantly changed.
But if I try to do the same in Windows, that is I have kept the PDF open with a PDF viewer, and I try to run the code, the following error will come --> cannot access pdf. Why there is a difference in behavior in Linux (I am working with Ubuntu 20.04)?
Adding the output of the Windows error
Error in pdf(file = "Forest_levels_2.pdf", width = 12, height = 12) :
cannot open file 'Forest_levels_2.pdf'
In order to remove some variables, I tried to download the Evince PDF viewer for windows (Evince 2.32) and then opened the PDF using Evince in Windows and did the same experiment again.
Guess what happened!?!
I was able to successfully modify the open PDF in Windows. Evince works same in both Ubuntu and Windows. So probably, it is more dependent on the property of PDF viewer also.
R
to write in it when it is open. I have not tried with different viewer in Windows. Will do it. The error is issued byR
that the file is unable to be accessed in Windows. In Ubuntu, no such error surfaces.