将R绘图复制到具有自定义大小的剪贴板

编程入门 行业动态 更新时间:2024-10-26 08:35:25
本文介绍了将R绘图复制到具有自定义大小的剪贴板的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

有没有一种方法可以让R / RStudio以自定义尺寸将剪贴画复制到剪贴板?

RStudio具有此功能,但您必须定义大小每次,并有一些额外的点击,我肯定是可以避免的。

我尽我所能保存为jpeg或其他与 file =剪贴板,然后 - 绘制后 - dev.off()。没有错误信息,但剪贴板中也没有。

以下是一个例子:

data(mtcars) jpeg(file =clipboard,width = 800,height = 600,units =px,pointsize = 12, quality = 100, bg =white,res = NA,family =,restoreConsole = T) hist(mtcars $ mpg) dev.off()

p>

关于如何实现这一点的任何想法?

解决方案

最好的办法是能够控制Rstudio的大小,但正如你从Rstudio网站上发现你自己的,Rstudio不支持这一点。以下代码将您的绘图保存到wmf。还有一个解决方法是保存到位图,其中包含一些点击操作,但至少不必再指定大小:

data(mtcars) windows(800,600,po​​intsize = 12)#打开一个单独的窗口,其大小为 hist(mtcars $ mpg)#draw to this(active) window savePlot(clipboard,type =wmf)#saves plot to WMF

不幸的是,将剪贴板保存为 jpg 格式似乎是不可能的。点击 CTRL-C ,你可以将它复制到一个位图上,并且图形以800:600的位图位于剪贴板上。

编辑: windows 命令仅适用于Windows。 Mac <它应该被替换为: quartz(width = 8,height = 6,pointsize = 12,dpi = 100)(width / height in inches! p>

对于 linux 尝试 x11(width = 8,height = 6,pointsize = 12,dpi = 100)(未经测试)。

Is there a way to get R / RStudio to copy a plot to the clipboard with a custom size?

RStudio has this function, but you have to define the size everytime and there is some extra clicking which I am sure is avoidable.

I tried my best with saving as jpeg or else with file="clipboard" and then - after plotting - dev.off(). No error messages, but also nothing in the clipboard.

Here is an example:

data(mtcars) jpeg(file = "clipboard",width = 800, height = 600, units = "px", pointsize = 12, quality = 100, bg = "white", res = NA, family = "", restoreConsole = T) hist(mtcars$mpg) dev.off()

Any ideas on how this can be achieved?

解决方案

The best way would be to be able to control the size in Rstudio, but as you have found out yourself from the Rstudio-website, Rstudio doesn't support that. The following code saves your plot to wmf. There is also a workaround to a save to bitmap, which involves some clicking, but at least you don't have to specify the size any more:

data(mtcars) windows(800, 600, pointsize = 12) #opens a separate window with the size you want hist(mtcars$mpg) #draw to this (active) window savePlot("clipboard", type="wmf") #saves plot to WMF

Unfortunately, it seems to be impossible to save to jpg format to the clipboard. You can copy it to a bitmap by going to this window, click CTRL-C and the graph is on the clipboard as bitmap with 800:600.

EDIT: The windows command only works on Windows. For Mac, it should be replaced by: quartz(width=8,height=6,pointsize=12,dpi=100) (width/height in inches!)

For linux try x11(width=8,height=6,pointsize=12,dpi=100) (untested).

更多推荐

将R绘图复制到具有自定义大小的剪贴板

本文发布于:2023-07-15 10:16:14,感谢您对本站的认可!
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:剪贴板   自定义   大小

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!