相关疑难解决方法(0)

将绘图保存为pdf并同时在窗口中显示(x11)

我写了一个创建条形图的函数.我想将这个图保存为pdf,并在应用此功能时将其显示在我的屏幕(x11)上.代码看起来像这样.

create.barplots <- function(vec)
 {
   x11()                                  # opens the window
   ### Here is a code that creates a barplot and works perfectly
   ### but irrelevant for my question
   dev.copy(pdf("barplots.table.2.pdf")) # is supposed to copy the plot in pdf
                                         # under the name "barplots.table.2.pdf"
   dev.off()                             # is supposed to close the pdf device
 }
Run Code Online (Sandbox Code Playgroud)

这会产生以下错误:'device'应该是一个函数

当我将代码修改为:

create.barplots <- function(vec)
 {
   x11()
   ### Here is a code that creates a barplot and works perfectly
   ### but irrelevant for my question
   dev.copy(pdf) # …
Run Code Online (Sandbox Code Playgroud)

r

18
推荐指数
3
解决办法
2万
查看次数

标签 统计

r ×1