R 当annotate()层的标签有下标时,ggsave()不工作

R 当annotate()层的标签有下标时,ggsave()不工作,r,ggplot2,plot,R,Ggplot2,Plot,我正在尝试将包含下标的标签添加到绘图中。代码在R studio中运行良好,但使用ggsave()导出图形时,我会出现以下错误: Error in grid.Call.graphics(C_text, as.graphicsAnnot(x$label), x$x, x$y, : Metric information not available for this family/device 以下是我的数据: dput(LLTemp_wide) structure(list(Temp = c

我正在尝试将包含下标的标签添加到绘图中。代码在R studio中运行良好,但使用ggsave()导出图形时,我会出现以下错误:

Error in grid.Call.graphics(C_text, as.graphicsAnnot(x$label), x$x, x$y,  : 
  Metric information not available for this family/device
以下是我的数据:

dput(LLTemp_wide)
structure(list(Temp = c(-15, -20, -22.5, -25, -30), Alive = c(5L, 
4L, 2L, 1L, 0L), Dead = c(0L, 2L, 4L, 5L, 5L), Prop_Survival = c(1, 
0.6666, 0.3333, 0.1666, 0)), class = "data.frame", row.names = c(NA, 
-5L))
正在使用的软件包:

library(plyr)
library(MASS)
library(ggPredict)
library(dplyr)
library(ggplot2)
我的代码是:

# theme adjustments
Alex_Theme = theme_bw() +
  theme(plot.title = element_text(hjust = 0.5, face='plain', size = 12)) +
  theme(plot.title = element_text(vjust=-1.8)) +
  theme(plot.subtitle=element_text(size=10, hjust=0.5, face="italic", color="black")) +
  theme(legend.position="none") +
  theme(panel.border = element_rect(fill=NA, colour = "black", size=0.5)) +
  theme(axis.text = element_text(face = "plain", size = 10)) +
  theme(axis.title.x = element_text(margin = margin(t = 8, r = 20, b = 0, l = 0))) +
  theme(axis.title.y = element_text(margin = margin(t = 8, r = 6, b = 0, l = 0))) +
  theme(panel.grid.major = element_blank(), panel.grid.minor = element_blank()) +
  theme(axis.title = element_text(face="plain", size = 10))

ggplot(LLTemp_wide, aes(x = Temp, y = Prop_Survival)) +
  Alex_Theme +
  #ggtitle("UIC: Lower lethal temperature") +
  #theme(plot.title = element_text(size = 10, vjust = 0.5)) +
  xlab("Temperature (°C)") +
  ylab("Survival Probibility") +
  geom_segment(aes(x = -21.4917, y = -Inf, xend =  -21.4917, yend = 0.5), linetype = 2, color = 'grey50') + # LT50 vertical line
  geom_segment(aes(x = -Inf, y = 0.5, xend = -21.4917, yend = 0.5), linetype = 2, color = 'grey50') + # LT50 horizontal line
  geom_segment(aes(x = -25.35566, y = -Inf, xend =  -25.35566, yend = 0.1), linetype = 2, color = 'grey50') + # LT10 vertical line
  geom_segment(aes(x = -Inf, y = 0.1, xend = -25.35566, yend = 0.1), linetype = 2, color = 'grey50') +  # LT10 horizontal line
  geom_segment(aes(x = -17.62774, y = -Inf, xend =  -17.62774, yend = 0.9), linetype = 2, color = 'grey50') + # LT90 vertical line
  geom_segment(aes(x = -Inf, y = 0.9, xend = -17.62774, yend = 0.9), linetype = 2, color = 'grey50') +  # LT90 horizontal line
  stat_smooth(method = "glm", 
              method.args = list(family = quasibinomial(link = 'logit')),
              se = FALSE,
              colour = "red") +
  geom_point() +
  annotate(geom = "text", x = -29, y = 0.55, size = 3, parse = TRUE, label = as.character(expression(paste(LT[50], "= -21.5 °C")))) +
  annotate(geom = "text", x = -33, y = 0.15, size = 3, parse = TRUE, label = as.character(expression(paste(LT[90], "= -25.4 °C")))) +
  annotate(geom = "text", x = -25, y = 0.95, size = 3, parse = TRUE, label = as.character(expression(paste(LT[10], "= -17.6 °C")))
  )

  ## Save Plot
ggsave("ALB_Lethal_Temp.png", width = 3.5, height = 4, type = "cairo-png")
以下是控制台中情节的屏幕截图(似乎工作正常…):

在ggsave()导出之后,我得到的结果是:


如果从标签中删除表达式并只打印文本,则ggsave()导出工作正常。这是ggsave问题还是我的代码有问题?

在Linux上适用。你在使用Windows吗?也许使用cairo设备会有所帮助。e、 或者pdf对我来说很好,但是标签太大了。另外,只需删除
,type=“cairo png”
就可以将其保存在windows上而不会出现问题。ggplot知道,您希望文件名中的文件扩展名包含png