【问题标题】:Italic and not-italic words in legend in R?R中传说中的斜体和非斜体字?
【发布时间】:2019-03-26 14:27:19
【问题描述】:

我需要绘制一段时间内发现的紫罗兰标本的数量。在图例中,我想显示 2 个观察到的物种以及它们的总和。为了写出科学的正确性,我还需要“中提琴规格之和”中的“中提琴”斜体。

我想和theforestecologist 在他的顶级传奇中实际上相同,但我无法用文字重现他的例子。所以我使用text.font() 以一种简单的方式做到了这一点,但整行都是斜体。我在main() 中使用的代码缩写没有帮助。 是否可以在图例中只写一部分斜体?

vr <- sample(1:100, 10, replace = TRUE)
vo <- sample(1:100, 10, replace = TRUE)
date <- Sys.Date() + sort(sample(1:10, 10))
vs <- vr + vo
df <- data.frame(vr, vo, date, vs)

plot(
  vs ~ date,
  data = df,
  type = "o",
  ylim = c(0, max(df$vs)),
  col = "black",
  pch = 13,
  cex = 1.2,
  lwd = 2,
  main = expression(paste(italic('Viola'), " spec. [ind]")),
  ylab = "Amount"
)
lines(
  vr ~ date,
  data = df,
  type = "o",
  col = "RoyalBlue2",
  pch = 1,
  cex = 1.2
)
lines(
  vo ~ date,
  data = df,
  type = "o",
  col = "springgreen3",
  pch = 4,
  cex = 1.2
)
legend(
  "topright",
  inset = c(0.01 , 0.02),
  c("Sum of Viola spec.", "Viola odorata", "Viola reichenbachiana"),
  xpd = TRUE,
  pch = c(13, 1, 4),
  pt.cex = 1.2,
  col = c(1, "RoyalBlue2", "springgreen3"),
  cex = .9,
  y.intersp = .9,
  bty = "l",
  bg = rgb(244, 248, 249, max = 255),
  text.font = c(1, 3, 3)
)

【问题讨论】:

    标签: r


    【解决方案1】:

    为什么不使用 expression()italic() 就像您在标题中所做的那样?

    legend(
      "topright", 
      inset=c(0.01 ,0.02), 
      c(expression(paste("Sum of ", italic('Viola'), " spec.")), 
        expression(italic("Viola odorata")), 
        expression(italic("Viola reichenbachiana"))
        ), 
      xpd = TRUE,
      pch = c(13, 1, 4), pt.cex=1.2, 
      col = c(1,"RoyalBlue2", "springgreen3"), 
      cex = .9, y.intersp=.9, bty = "l", 
      bg = rgb(244, 248, 249, max = 255), 
      text.font = c(1,3,3)
    )
    

    【讨论】:

    • 我真的不知道我是怎么错过的。我确实尝试过,但我只尝试在那一行中使用expression(),这一定是我的错误。非常感谢!
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2010-12-13
    • 2011-07-18
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2014-11-02
    相关资源
    最近更新 更多