如何在基数R中的图例中使单词变成斜体

时间:2018-09-25 17:47:05

标签: r plot legend

我有这段代码,我无法破解。我想在图例中用斜体字表示一个单词,然后循环使用。代码行以粗体显示。

legend('top', paste(italic(increase$Gene[i]), increase$Sex[i], increase$Drug[i]), bty='n', text.font=2, cex=4.0)

这将非常有帮助。到目前为止,在线仍然没有帮助。

请参阅附加代码:

pdf(file= "/Users/cahighfi/Desktop/MaleCocaineConsumptionPlots_UbiInc.pdf", width = 30, height = 30);
par(mfrow = c(4, 4),     # 2x2 layout
      oma = c(2, 2, 0, 0), # two rows of text at the outer left and bottom margin
      mar = c(5, 5, 2, 1)+0.1, # space for one row of text at ticks and to separate plots
      mgp = c(2, 1, 0),    # axis label at 2 rows distance, tick labels at 1 row
      xpd = NA) 
x<-1:3
for (i in 1:nrow(increase)) {
  plot(x=c(1, 3), increase[i,2:3], type="o", col= "red1", ylim=c(-40,40), cex.main=3.0, ylab ="", xlab="", axes=F, lwd=8)
  axis(side=1, at=c(1,3), labels=c(1,3), cex.axis=3.0, font = 2)
  axis(side=2, cex.axis=3.0, font = 2)
  box()
  lines(x=c(1, 3), increase[i,4:5], type="o", col= "blue1", lwd=8)
  legend('top', paste(italic(increase$Gene[i]), increase$Sex[i], increase$Drug[i]), bty='n', text.font=2, cex=4.0)
  legend('bottom', paste("P", "=", increase$p.value_chng_pref[i]), text.font=4, cex=4.0, bty='n')
   mtext("Preference", side=2, line=3.25, cex=2.5, font = 2);
   mtext("Exposure", side=1, line=2, cex=2.5, font = 2);
 }
 dev.off()
 graphics.off()

0 个答案:

没有答案