如何在R中的同一图中上标和斜体

时间:2018-12-19 13:59:36

标签: r legend superscript italics

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

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 ~)

它可以单独工作,但是当我组合其他三个标签时似乎不起作用。我也迷失了如何仅将 TOC1 变为斜体,并尝试了此处概述的方法:How to only make one legend name italic in base R plot? 没有运气。 任何帮助将不胜感激!

到目前为止的

代码:

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)

1 个答案:

答案 0 :(得分:4)

您可以在图例中将上标和斜体文本组合在一起,

"dependencies": {
    "@angular/animations": "6.1.0",
    "@angular/common": "6.1.0",
    "@angular/compiler": "6.1.0",
    "@angular/compiler-cli": "6.1.0",
    "@angular/core": "6.1.0",
    "@angular/fire": "^5.1.0",
    ....
    "@ionic-native/camera": "^5.0.0-beta.22",
    "@ionic-native/core": "^5.0.0-beta.22",
    ...
    "cordova-plugin-camera": "~4.0.3",
    ...
    "firebase": "^5.5.9",
    "ionic-angular": "3.9.2",
    "promise-polyfill": "^8.1.0",
    "rxjs": "^6.3.3",
    "rxjs-compat": "^6.3.3",
    "cordova-android": "~7.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')))) 表示上标格式的结尾。应将斜体文本放在*

输出:

enter image description here

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

expression(...)