【问题标题】:Saving ggplot in EPS format for editing in Adobe Illustrator -- problem with text以 EPS 格式保存 ggplot 以在 Adob​​e Illustrator 中进行编辑——文本问题
【发布时间】:2024-01-12 21:39:01
【问题描述】:

问题

我想从 R 中保存 ggplot,以便在 Adob​​e Illustrator (AI) 中进行编辑。我可以使用ggsaveEPSPS 格式保存绘图,但绘图总是在文本周围带来一些阴影。有没有办法在 R 或 Adob​​e Illustrator 中解决这个问题?

例如,我的plot 是这样的:

但是,当我将它导入 AI 时,它看起来像这样(文本周围的粉红色阴影):

代码

# Saving a plot for editing in Adobe Illustrator.

library(ggplot2) # for plotting
library(cowplot) # for ggsave

# Generate an example scatter plot.
# From: http://r-statistics.co/Top50-Ggplot2-Visualizations-MasterList-R-Code.html
options(scipen=999)  # turn-off scientific notation like 1e+48
theme_set(theme_gray())  
data("midwest", package = "ggplot2")

plot <- ggplot(midwest, aes(x=area, y=poptotal)) + 
  geom_point(aes(col=state, size=popdensity)) + 
  geom_smooth(method="loess", se=F) + 
  xlim(c(0, 0.1)) + 
  ylim(c(0, 500000)) + 
  labs(subtitle="Area Vs Population", 
       y="Population", 
       x="Area", 
       title="Scatterplot", 
       caption = "Source: midwest")
plot

# Save the plot as .eps with ggsave. 
file <- "myplot.eps"
ggsave("myplot.jpg",plot)

【问题讨论】:

    标签: r ggplot2 adobe-illustrator cowplot


    【解决方案1】:

    2020 年 11 月 3 日更新

    我现在确保在生成任何绘图之前已将字体设置为“Arial”。您可以使用extrafont 包设置自定义字体。

    library(extrafont)
    
    font_import(path=font_path, prompt=FALSE)
    
    fonts() # check to see which fonts are available
    
    choose_font("Arial")
    
    # plotting code ...
    

    font_path 指定包含所需“字体”的目录的路径,例如arial.ttf.

    旧的部分解决方案

    我为这个糟糕的问题道歉。导入 Adob​​e Illustrator 后,绘图文本后面的粉红色阴影表示该字体未被 AI 识别。如果你从 AI 导出绘图,这个阴影就消失了。

    要向 AI 添加字体,您可以尝试按照以下说明操作:

    向 Adob​​e Illustrator 添加新字体

    Source

    • 创建一个新的 AI 文档(文件 > 新建)
    • 开始输入新文档。
    • dafont.com下载橙汁字体。
    • 解压文件(橙汁2.0.ttf)
    • 安装 TrueType 文件(右键单击 > 安装)。
    • 现在应该可以在 AI 中识别字体。

    检查 ggplot 使用的是哪种字体:

    > mytheme <- ggplot2::theme_gray()
    > mytheme$family
    [1] "" # The default is sans.
    
    # To check which sans font is being used:
    > windowsFonts()
    $`serif`
    [1] "TT Times New Roman"
    
    $sans
    [1] "TT Arial" 
    
    $mono
    [1] "TT Courier New"
    
    # My PC's default sans font is TT Arial.
    '''
    

    【讨论】:

    • 你的问题其实很好。但是你应该通过解释为什么安装orange juice字体有帮助来改进你的答案,而使用的字体大概是TT Arial?之后你在illustrator中没有得到粉红色的盒子吗?
    • 好吧,我实际上被困在这一点上。尽管我能够将字体添加到 AI 或将 ggplot 中使用的字体更改为 AI 使用的字体,但绘图的文本仍未正确导入 AI。我得出的最终解决方案是将 ggsave 保存为 .eps,然后一次更改 AI 中的所有字体。
    【解决方案2】:

    由于您已经在使用ggplot2,您可以将最后一行更改为

    ggsave("myplot.eps",plot)
    

    setEPS()
    postscript("whatever.eps")
    #Plot Code
    

    点击以下链接了解其他可能的解决方案:

    Export a graph to .eps file with R

    确保您导出可以通过图形编辑器编辑的文档。您需要为图形编辑器支持的绘图选择一个主题(包括字体等)。

    请参阅以下链接以获取 GGPLOT2 主题文档:

    https://ggplot2.tidyverse.org/reference/theme.html

    https://www.rdocumentation.org/packages/ggplot2/versions/2.1.0/topics/theme

    【讨论】:

    • 感谢您指出错误。我意识到我没有尝试从 AI 导出图像,当我这样做时,粉红色的阴影消失了。我猜它的人工智能试图告诉我一些事情。这是一个糟糕的问题。
    最近更新 更多