ggplot2中带注释的逗号和撇号

我想用逗号创建一个标签,如下所示:

label2 <- "epsilon[f[c]']"
label3 <- "epsilon[f[c],adj]"

我使用以下内容:

... + annotate("text", x = -0.003, y= -0.25, label = label2, size = fontsize, 
          family = "sans", parse = TRUE) +
      annotate("text", x = -0.003, y= -0.25, label = label3, size = fontsize, 
          family = "sans", parse = TRUE)

但对于label2:需要删除'才能使代码运行并 对于label3:下标忽略“ ult”之后的所有内容

编辑:

数据:

> dput(material)
structure(list(strain = c(-0.00375, -0.00248, -0.00195, -0.00121, 
-0.000248, 0, 0.000132, 0.00145, -0.0046736, -0.0034036, -0.0028676, 
-0.0021336, -0.0011707, -0.0009226), stress = c(-4.6011, -5, 
-4.8555, -3.9414, -0.9901, 0, 0.5303, 0, -4.6011, -5, -4.8555, 
-3.9414, -0.9901, 0), type = structure(c(1L, 1L, 1L, 1L, 1L, 
1L, 1L, 1L, 2L, 2L, 2L, 2L, 2L, 2L), .Label = c("Standard 5 ksi Concrete", 
"Adjusted 5 ksi Concrete"), class = "factor")), row.names = c(NA, 
-14L), class = "data.frame")

情节:

plot <- ggplot(material) + theme_void() +
 aes(x = strain, y = stress, colour = type, group = type) +
 geom_xspline(size = 0.7, spline_shape = 0.5) + labs(x = "Strain (in/in)", 
 y = "Stress (ksi)", color = element_blank()) + theme(legend.position = "bottom", 
   axis.title.y = element_text(size=10, colour="black", angle = 90, vjust = -22, hjust = 0.55),
   axis.title.x = element_text(size=10, colour="black", vjust = 4, hjust = 0.6),
   axis.text.y = element_blank(), axis.text.x = element_blank(),
   legend.text=element_text(size=10), legend.direction="vertical",
   legend.spacing.x = unit(0, 'cm')) + scale_colour_manual(values = 
    c("Standard 5 ksi Concrete" = "blue", "Adjusted 5 ksi Concrete" = "red")) +
  scale_y_continuous(trans = "reverse") + scale_x_continuous(trans = "reverse") + 
  geom_vline(aes(xintercept = 0), size = 0.3) + geom_hline(aes(yintercept = 0), size = 0.3) + 
  geom_segment(aes(x = 0, y = 0, xend = -0.0009226, yend = 0), size = 0.7) +
  geom_segment(aes(x = -0.0009226, y = 0, xend = -0.0011707, yend = -0.94), size = 0.7) +
  geom_segment(aes(x = 0, y = -4.958, xend = -0.00333, yend = -4.958), 
           size = 0.6, linetype = "dotted", colour = "black") +
  geom_segment(aes(x = -0.00333, y = 0, xend = -0.00333, yend = -4.958), 
           size = 0.6, linetype = "dotted", colour = "black") +
  geom_segment(aes(x = -0.0024, y = 0, xend = -0.0024, yend = -4.958), 
           size = 0.6, linetype = "dotted", colour = "black") +
  geom_segment(aes(x = -3.75E-03, y = 0, xend = -3.75E-03, yend = -4.6011), 
           size = 0.6, linetype = "dotted", colour = "black") +
  geom_segment(aes(x = -0.0046736, y = 0, xend = -0.0046736, yend = -4.6011), 
           size = 0.6, linetype = "dotted", colour = "black") +
  annotate("text", x = 0.0002, y= -5, label = label0, size = fontsize, family = "sans", parse = TRUE) +
  annotate("text", x = -0.0006, y= 0.2, label = label1, size = fontsize, family = "sans", parse = TRUE) +
  annotate("text", x = -0.0021, y= -0.25, label = label2, size = fontsize, family = "sans", parse = TRUE) +
  annotate("text", x = -0.003, y= 0.2, label = label3, size = fontsize, family = "sans", parse = TRUE) +
  annotate("text", x = -0.0041, y= -0.25, label = label4, size = fontsize, family = "sans", parse = TRUE) +
  annotate("text", x = -0.0045, y= 0.2, label = label5, size = fontsize, family = "sans", parse = TRUE)
评论