首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >使用R创建锐化或锐化的图形以导入到PowerPoint中

使用R创建锐化或锐化的图形以导入到PowerPoint中
EN

Stack Overflow用户
提问于 2015-10-05 21:32:57
回答 2查看 350关注 0票数 0

这可能是重复的,尽管我在Google上找不到类似的帖子,也没有通过Stack Overflow上的Questions that may already have your answer功能找到类似的帖子。

我不确定用R创建清晰或锐利的图形的最佳方式,然后可以导入到例如PowerPoint中。

下面是创建PDF文件的代码。当导入到PowerPoint中时,生成的图像非常模糊,质量非常差。

接下来,我将展示使用Cairo包创建漂亮的清晰图像的代码和说明。但是,这涉及到将生成的文件导入到名为Inkscape的第三方软件中,并在将文件导入到PowerPoint之前将文件保存为新格式。

有没有一种方法可以创建漂亮的锐利图形,而不涉及将文件导入第三方软件的中间步骤?

感谢您的任何建议。如果这是重复的,很抱歉。代码如下:

代码语言:javascript
复制
setwd('c:/users/markm/simple R programs/')

a <- seq(1,20)
b <- a^0.25
plot(a, b, bty = "l")

pdf("example_pdf_plot_Oct5_2015.pdf")
     plot(a, b, bty = "l")
     title('Example PDF Plot')
dev.off()

#
# After creating the file below with the Cairo package:
#
# 1. Install the free software 'Inkscape'
# 2. Open the *.svg file with Inkscape and save as a *.emf file.
# 2b. Click 'OK' when asked to convert texts to paths.
# 2c. Click 'Close without saving'
# 3. Import the *.emf file into PowerPoint as a picture.
# 4. Resize and position image in PowerPoint to taste.
#
# install.packages('Cairo')
library(Cairo)

CairoSVG('example_svg_plot_Oct5_2015.svg', onefile = TRUE, pointsize = 12, width=8, height=6, bg="white")
     plot(a, b, bty = "l")
     title('Example SVG Plot')
dev.off()
EN

回答 2

Stack Overflow用户

发布于 2015-10-06 20:49:51

您可以查看ReporteRs

代码语言:javascript
复制
library(ReporteRs)

my_graph_fun <- function( ){
  a <- seq(1,20)
  b <- a^0.25
  plot(a, b, bty = "l")  
}

doc = pptx()
doc = addSlide(doc, "Title and Content")
doc = addPlot(doc, fun = my_graph_fun )
writeDoc(doc, "example.pptx")
票数 1
EN

Stack Overflow用户

发布于 2015-10-05 21:34:58

下面是创建文件的R代码,该文件看起来与使用Inkscape创建的SVG文件一样清晰。不需要对TIFF文件进行中间编辑。只需将R创建的TIFF文件直接导入PowerPoint即可。

代码语言:javascript
复制
tiff(file = "example_tiff_plot_Oct5_2015.tiff", 
     compression= "lzw", width = 8, height = 6, res = 500, unit = "in", pointsize = 12)

     plot(a, b, bty = "l")
     title('Example Tiff Plot')

dev.off()

这是有人向我建议的另一种方法。这种png方法得到的文件在大小上比TIFF文件小,而且我猜可以更好地重缩放。

代码语言:javascript
复制
a <- seq(1,20)
b <- a^0.25

png(file = "example_png_plot_Oct6_2015.png", 
     width = 8, height = 6, res = 500, unit = "in", pointsize = 12)

     plot(a, b, bty = "l")
     title('Example Png Plot')

dev.off()
票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/32949931

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档