0

我正在尝试创建以下图例:

legend(x = 23, y = 40, legend = c('Col-0 Control', 'Col-0 840g ha-1', 'TOC1-ox Control', "TOC1 840g ha-1"), col = c('black', 'black','red', 'red'), lty = c(1,2,1,2 ), pch=c(15,15,15,15), pt.bg = c('white', 'white', NA,NA), cex = 1.5, bty="n", lwd=2)

哪个有效,但我试图获得上标格式 ha^-1 的 ha-1,同时也只制作斜体的TOC1(不是 -ox 或 840g ha-1)。我尝试了以下方法:

as.expression(bquote("Col-0 840g " ~ ha^-1 ~)

它单独工作,但当我结合其他 3 个标签时似乎不起作用。我也迷失了如何仅将TOC1斜体并尝试了此处概述的方法:如何在基本 R 图中仅使一个图例名称斜体? 没有运气。任何帮助将不胜感激!

到目前为止的代码:

windows(width=10, height=8)
windowsFonts(A = windowsFont("Times New Roman"))
plot.new()
op <- par(family="A", font=2)
plot(Exp24[1:3,12], Exp24[1:3,11], bty = "n", xaxt = "n", xlim=range(24:72), ylim=range(10:40), col = "black", type = "b", pch=15, cex=2, family = "A", xlab = "Time After Leaf Disc Extraction (h)", ylab = "Relative Electrolyte Leakage (%)", lty = 1, lwd=2, cex.lab =1.5, cex.axis=1.5, font=2, font.lab=2)
arrows(Exp24[1:3,12], Exp24[1:3,11]-Exp24[1:3,15], Exp24[1:3,12], Exp24[1:3,11]+Exp24[1:3,15], length=0.05, angle=90, code=3, col = "black", lwd=2)
axis(side=1,at=c(24,48, 72),labels=c("24","48","72"), font=2, cex.axis=1.5, family="A", lwd=2)
par(op)
legend(x = 23, y = 40, legend = c(expression('Col-0 Control'), expression('Col-0 840g ha'^'-1'), expression(italic('TOC1')*'-ox Control'), expression(italic('TOC1')*'-ox 840g ha'^'-1')), col = c('black', 'black','red', 'red'), lty = c(1,2,1,2 ), pch=c(15,15,15,15), pt.bg = c('white', 'white', NA,NA), cex = 1.5, bty="n", lwd=2)
par(op)
4

1 回答 1

4

您可以在图例中组合上标和斜体文本,如下所示:

# make a very simple plot
x <- c(1,3,6,9,12)
y <- c(1.5,2,7,8,15)
plot(x,y, xlab=expression('AB'^'superscript'* italic('some italic text'))))

星号*表示上标格式的结束。应该是斜体的文本被放置在italic(...)

输出:

在此处输入图像描述

现在,如果您的图例中有多个标签,只需将每个标签放在一个expression(...)函数中即可。像这样

c(expression('cars'), expression('trucks'^'trucks'* italic(trucks))
于 2018-12-19T14:21:26.520 回答