如何在R中的同一个图中上标和斜体
How to superscript and italicize in the same plot in R
我正在尝试创建以下图例:
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 设为斜体,并尝试了此处概述的方法:
没有运气。
任何帮助将不胜感激!!
到目前为止的代码:
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)
您可以像这样在图例中组合上标和斜体文本:
# 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))
我正在尝试创建以下图例:
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 设为斜体,并尝试了此处概述的方法:
到目前为止的代码:
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)
您可以像这样在图例中组合上标和斜体文本:
# 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))