我需要绘制发现的紫罗兰色标本随时间变化的曲线。在图例中,我想显示两个观察到的物种以及它们的总和。为了撰写科学正确的文章,我还需要在“中提琴规格总和”中为“中提琴”添加斜体。
我实际上希望与他的右上角传说中的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)
)
答案 0 :(得分: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)
)