问题
我想从R中保存一个ggplot,以便在Adobe (AI)中编辑。我可以用EPS或PS格式用ggsave保存这个情节,但是这个情节总是会给文本带来一些阴影。有没有办法在R或中解决这个问题?
例如,我的绘图如下所示:

但是,当我将它导入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)发布于 2019-06-12 14:10:09
更新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。
旧部分解
我为这个可怜的问题道歉。在将图形文本导入之后,后面的粉红色阴影表明该字体无法被AI识别。如果你从AI导出这个地块,这个阴影就消失了。
要向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.
'''发布于 2019-06-11 21:55:00
由于您已经在使用ggplot2,所以可以将最后一行更改为
ggsave("myplot.eps",plot)或
setEPS()
postscript("whatever.eps")
#Plot Code关于其他可能的解决方案,请按下面的链接:
若要确保导出可通过图形编辑器编辑的文档,请执行以下操作。您需要选择一个主题(包括字体等)用于图形编辑器支持的绘图。
有关GGPLOT2主题文档的链接如下:
https://ggplot2.tidyverse.org/reference/theme.html
https://www.rdocumentation.org/packages/ggplot2/versions/2.1.0/topics/theme
https://stackoverflow.com/questions/56551609
复制相似问题