Use yyplot to modify the font of ggplot2 drawing, causing the arrow position in the figure to shift

Hi, I am using ggplot2 to draw a scatter plot of PCA analysis. In order to make the results more intuitive, I used geom_label_repel to add labels and arrows. In addition, I want to modify the font in the figure and use yyplot. But after using yyplot to modify the font, the arrow in the figure shifted. As shown in the figure below, I tried some methods but couldn’t fix this error. In addition, I found that the arrow position is correct when I click to save the picture in Rstudio, but this error occurs when I run the R script to draw. Hope someone can help me solve this problem, thank you very much!

PCAplot <- ggplot(data_x, aes(PC1, PC2)) +
  geom_point(aes(color = Group), size = input$PCApointsize) +
  coord_equal(ratio = input$PCAratio) +
  xlab(xlab) +
  ylab(ylab) +
  geom_label_repel(data = data_x, aes(x = PC1, y = PC2, label = varnames, fill = Group),
                   size = input$PCAlabelsize, segment.size = input$PCASegsize,
                   arrow = arrow(length = unit(input$PCAunitvalue, "cm")),
                   nudge_x = input$PCAnudgex, nudge_y = input$PCAnudgey,
                   direction = "both", box.padding = unit(input$PCAboxunitvalue, 'lines'),
                   segment.color = input$segcolor, show.legend = FALSE)
PCAplot ![enter image description here][1]<- set_font(PCAplot, family = "Times", fontface = "italic", size = 3.8)
cowplot::plot_grid(PCAplot)

enter image description here

Read more here: Source link