如何在r-plot中更改字体类型

时间:2014-06-06 17:48:10

标签: r

在下面的图中我试图用Arial字体中的所有文本但是轴(x轴和y轴的编号都是Times New Roman,而legend和mtext是Arial。请有人建议我如何解决它

 ace_Obs= c(1.80,0.99,4.82,5.03,2.04,1.96,5.89,7.73,5.53,2.03,4.36,2.20,
             1.83,12.98,9.50,2.33,10.39, 10.08,6.80,6.28,3.84,10.08,12.96, 
             14.29,4.49,4.23,8.33,3.00,9.52,8.33,3.00,9.52)

 # plot 
 z = c(" "," "," "," "," "," "," "," "," "," "," ")
 x1 = seq(0.5, 32.5, 1)
 y1 = rep(0,33)
 x <- seq(1, 32, 1)

 the_plot <- function()
 {
   plot(x1, y1, ylim = c(0,25),xlab = " ",ylab = " ",type = "l", xaxt='n',
        yaxt='n', main = " ")
   points(x = x, y = ace_Obs, col = "black", cex = 1.5)
   legend(x = -1.3, y = 25, "Nov", cex = 2.2, text.font=2, box.lwd = 1)
   x2 = seq(1982,2013,3)
   mtext(expression("ACE" ~ (m^{2} ~ s^{-1} ~ "")), 
         side=2,line=2.7, 
         font = 6, cex = 2)
   axis(1,at=seq(1, 32, by=3), labels=x2, las=2, font = 6)
   axis(2,at=seq(0,25, 5), labels=c("0","5","10","15","20","25"), 
        las=2, font = 6)
 }

 png("TEST.png",width = 6,height = 4,units = "in",res = 1000, pointsize = 6)
 par(mfrow = c(1,1),
     oma = c(5,5,0,0) + 0.1,
     mar = c(0.5,0.5,1,1) + 0.1, xaxs = "i", yaxs = "i", cex.axis = 2,
     cex.lab  = 2,cex.main  = 2)
 the_plot()
 dev.off()

1 个答案:

答案 0 :(得分:0)

对某人有帮助,因为上面提到的问题(对于png out put)使用type = "cairo"如下:

png("GFDL_ace_Forecast11.png",width = 6,height = 8,units = "in",res = 1000, pointsize = 7, type = "cairo")