axis.Date用另一种语言

时间:2013-03-26 00:53:12

标签: r

我正在根据日期(x轴)绘制现象的出现。问题是,在R中使用axis.Date函数时,日期轴是法语。我希望它是英文的。对不起,如果这是一个简单的问题,但我无法找到答案。

这就是我的所作所为。

date <- as.Date(c("2011/5/12","2011/5/13","2011/5/14","2011/5/15","2011/5/16","2011/5/17","2011/5/18","2011/5/19","2011/5/20","2011/5/21","2011/5/22","2011/5/23","2011/5/24","2011/5/25","2011/5/26","2011/5/27","2011/5/28","2011/5/29","2011/5/30","2011/5/31","2011/6/1","2011/6/2","2011/6/3","2011/6/4","2011/6/5","2011/6/6","2011/6/7","2011/6/8","2011/6/9","2011/6/10","2011/6/11","2011/6/12","2011/6/13","2011/6/14","2011/6/15","2011/6/16","2011/6/17","2011/6/18","2011/6/19"))
example <- c(0, 0, 0, 1, 0, 0, 0, 0, 1, 0, 1, 0, 3, 1, 1, 2, 5, 1, 3, 3, 8, 2, 1, 1, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0)

plot(date, example,xlab="Date of birth", axes=F,ylab="", ylim=c(0,15), yaxt="n", xaxt="n",lwd= 10,type="h", cex.lab=1.2, cex.axis=1, cex=1)
axis(2, at=seq(0,15, 5), lwd=1, cex=1)
axis.Date(1, at=seq(as.Date("2001/5/12"), as.Date("2011/6/19"), "weeks"), cex.axis=1, lwd=1)

但如果这是系统配置问题,您可能看不到x标签是法语。

谢谢!

1 个答案:

答案 0 :(得分:1)

您可以这样做:

old.loc <- Sys.getlocale("LC_TIME")
Sys.setlocale("LC_TIME", "English") 
axis.Date(1, at=seq(as.Date("2001/5/12"), as.Date("2011/6/19"), "weeks"), 
          cex.axis=1, lwd=1)
Sys.setlocale("LC_TIME",old.loc) 

但最好使用format的{​​{1}}参数来设置所需的格式。