Jude
Jude

Reputation: 193

Export ggplot to eps and keep text as text element

I would like to export a graph from ggplot to .eps format so I can edit it in illustrator software (I use Affinity Designer). My problem is that when I open the eps file, text is considered as vector shapes and not text. It would be easier and faster if text elements are exported directly as text and this seems possible from other posts I've read.

I plot my graph with the following code - there isn't anything really special happening here:

mosai %>%
  ggplot(aes(x = Elements_mosai, y = Area_km2, fill = Période)) + 
  geom_bar(stat = "identity", width = 1, position = "dodge") + 
  scale_fill_manual(breaks = c("Avant restauration","Pendant restauration", "Après restauration"), 
values = c("#E7298A", "#A6761D", "#66A61E")) +
      labs(x = "Eléments de la mosaïque paysagère", y = "Superficie (km2)") + 
      facet_wrap(~ Rivière + Type) + 
      theme_bw()

I am using theme_bw from ggplot which uses the font "TT Arial", here is more informations on that:

List of 11
 $ family       : chr ""
 $ face         : chr "plain"
 $ colour       : chr "black"
 $ size         : num 11
 $ hjust        : num 0.5
 $ vjust        : num 0.5
 $ angle        : num 0
 $ lineheight   : num 0.9
 $ margin       : 'margin' num [1:4] 0points 0points 0points 0points
  ..- attr(*, "unit")= int 8
 $ debug        : logi FALSE
 $ inherit.blank: logi TRUE
 - attr(*, "class")= chr [1:2] "element_text" "element"

> windowsFonts()
$serif
[1] "TT Times New Roman"

$sans
[1] "TT Arial"

$mono
[1] "TT Courier New"

I then save my plot with this command:

ggsave("test.eps", device = "eps", plot = last_plot(), path = DIR_OUT, width = 40, 
height = 20, units = "cm", dpi = 500)

Maybe there is a parameter to make ggsave save text as text?

EDIT 1

In response to Andy Baxter's comment, here is a screenshot of my eps file opened in a text viewer. Beginning of the file

End of the file

Upvotes: 0

Views: 402

Answers (0)

Related Questions