Vanishing symbol when saving graphic image

Asked

Viewed 40 times

2

In the annotations inserted by the argument annotate in the chart below in one of them has the symbol " ", but when saving the image as PDF the symbol disappears and appears "..." instead.

I’d like to keep it even after saving, is there any way?

Follow the command used and an image illustrating the example.

    library(ggplot2)
    dt <- data.frame(periodo = c("JUN", "JUL"), 
             peso = c(9.38, 26.14,16.27,47.71))
    dt$Variedade <- rep(c("6654", "9002"), each = nrow(dt)/2)
    dt$periodo <- factor(dt$periodo, levels = c("JUN", "JUL"))
    theme_patrick <- function(){ 
    theme(axis.title.y=element_blank(),
      axis.text.y=element_blank(),
      axis.ticks.y=element_blank(),
      axis.text.x=element_text(face = "bold", color = "black", size = 15),
      legend.text = element_text(size = 15),
      plot.subtitle = element_text(size = 12, face = "bold", hjust = 0, vjust = 2))}
   ggplot(dt, aes(x = periodo, y = peso)) +
   geom_col(aes(fill = Variedade), position = "dodge") +
   geom_label(aes(label = peso, colour = Variedade),
         fill = NA,
         position = position_dodge(width = 1),
         size = 5,
         fontface = "bold", vjust = -0.1, 
         show.legend = FALSE) +
   labs(x = "Período", y = "", title = "", subtitle = "Evolução peso")+
   scale_y_continuous(limits = c(0,80))+
   scale_fill_manual(values = c("brown1", "blue")) +
   scale_colour_manual(values = c("brown1", "blue")) +
   theme_patrick()+
   annotate(geom = "label", x = c("JUN","JUL"), y = c(20,40), label = c("≠6.89 kg","≠21.57 
   kg"), fontface = "bold", size = 5)+
   annotate(geom = "label", x = c(1.89,2.39), y = c(28.3,50), label = c("+16.76 kg","+31.44 
   kg"), colour = c("brown1","blue"), fontface = "italic", size = 5)
     

Gráfico ilustrativo

  • It is obvious that the font used to display on the screen is different from the one used in the PDF, and the second source does not have this symbol. I suggest choosing a specific source, then it will appear in both media, or in no.

  • @epx the font format that speaks is the font type ?

1 answer

4


Not all fonts and glyphs are supported by the driver postscript. The simplest way to solve is to use the driver cairo. It is not supported by ggsave, then open the device manually. Here’s a minimal example with your data:

library(ggplot2)

p <- ggplot(dt, aes(x = periodo, y = peso, fill = Variedade)) +
       geom_col(position = "dodge") +
       annotate(geom = "label", x = c("JUN","JUL"), y = c(20,40), label = c("≠6.89 kg","≠21.57 kg"))

cairo_pdf("plot.pdf", width = 6, height = 4)
p
dev.off()
  • When running the command does not appear at the end the plotted graph, how can I open it manually ? it goes to a specific folder ? Appears only "null device 1 "

  • 1

    Does not appear on the screen because the chart was sent directly to the device cairo_pdf. The archive Plot.pdf was saved to your working directory. To display the chart, just run p (outside the open device).

Browser other questions tagged

You are not signed in. Login or sign up in order to post.