How to copy plots in R when working in Ubuntu?

半世苍凉 提交于 2019-12-22 11:01:15

问题


I am working on the most recent of R on Ubuntu. After I created some plots, the cursor became a '+' and won't let me access the copy and paste options. Moreover unlike the R in Windows, it does not have a toolbar that have the 'Copy' option. What can I do to copy my plots?

Thank you.


回答1:


The default graphics device when using R under Linux is something called "X11": basically, it creates the window in which you see your plot.

It's a very basic window without many features so the answer is: you can't copy/paste from it. Instead, you need to create a different graphics device and write the plot to it. Most people would choose something like a PNG file, like this:

png(file = "myplot.png")  # create PNG device
plot(x)                   # do the plot
dev.off()                 # return to default device (X11)

And you now have a PNG file named "myplot.png" in the current directory.




回答2:


Neil provides part of the answer. Basically, the stock Ubuntu build gives you

  • pdf() for what may be the best format for publication graphics
  • png() for what may be useful on the web
  • jpeg()

as well as the abilty to write the current plot via dev.copy().

But then there is CRAN and a whole slew of add-on packages, including some as binaries for Ubuntu:

  • cairoDevice via r-cran-cairoDevice in Ubuntu

plus at least one other Cairo package or rforge.net, and at least abother SVG package can all write scalable vector graphics (SVG).

In the end it all depends on what you want to do with the graph file. Which you didn't say so it is hard to be specific.




回答3:


If you want GUI like options like RGUI I would suggest you use RStudio on Ubuntu (as well as on any other OS; http://rstudio.org/).



来源:https://stackoverflow.com/questions/6838851/how-to-copy-plots-in-r-when-working-in-ubuntu

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!