r - 将 ggplot 保存为 EPS 格式以便在 Adob​​e Illustrator 中进行编辑——文本问题

标签 r ggplot2 adobe-illustrator cowplot



我想保存一个 ggplot来自 R 用于在 Adob​​e Illustrator (AI) 中进行编辑。我可以将情节保存在 EPS 中或 PS格式为 ggsave ,但情节总是在文本周围带来一些阴影。有没有办法在 R 或 Adob​​e Illustrator 中解决这个问题?

例如,我的 plot看起来像这样:

png

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

screenshot

代码

# 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)

最佳答案

更新 11/03/2020
我现在确保在生成任何绘图之前我已经将字体设置为“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.
    '''
    

    关于r - 将 ggplot 保存为 EPS 格式以便在 Adob​​e Illustrator 中进行编辑——文本问题,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/56551609/

    相关文章:

    html - 如何制作悬停命令 = 悬停时的形状?

    r - 具有随机效应和 lsoda 的非线性回归

    r - 将值(行)插入数据框

    javascript - Adobe illustrator 脚本 (JavaScript) 初学者问题

    css - 使用 Adob​​e Illustrator 设置 CSS 类属性

    r - 按数据框中显示的降序绘制数据

    r - R 中分组日期内的填充

    r - 函数参数作为R函数中的参数

    r - 如何在值低于零时将线设为红色,在高于零时将线设为绿色?

    r - ggplot2:在每个方面从最高到最低重新排列条形