This question already has an answer here:
all x axis labels are not displaying in 45 degree

(1个答案)


7年前关闭。




我要绘制这些数据:
day                 temperature
02/01/2012 13:30:00     10
10/01/2012 20:30:00      8
15/01/2012 13:30:00     12
25/01/2012 20:30:00      6
02/02/2012 13:30:00      5
10/02/2012 20:30:00      3
15/02/2012 13:30:00      6
25/02/2012 20:30:00     -1
02/03/2012 13:30:00      4
10/03/2012 20:30:00     -2
15/03/2012 13:30:00      7
25/03/2012 20:30:00      1

在x轴上,我只想标记旋转45度的月份和日期(例如Jan 02)。如何使用命令plot()执行此操作?

最佳答案

使用基本图形:

tab <- read.table(textConnection('
"02/01/2012 13:30:00"     10
"10/01/2012 20:30:00"      8
"15/01/2012 13:30:00"     12
"25/01/2012 20:30:00"      6
"02/02/2012 13:30:00"      5
"10/02/2012 20:30:00"      3
"15/02/2012 13:30:00"      6
"25/02/2012 20:30:00"     -1
"02/03/2012 13:30:00"      4
"10/03/2012 20:30:00"     -2
"15/03/2012 13:30:00"      7
"25/03/2012 20:30:00"      1'))
tab[, 1] <- as.POSIXct(tab[, 1], format = "%d/%m/%Y %H:%M:%S")

plot(V2 ~ V1, data=tab, xaxt="n")
tck <- axis(1, labels=FALSE)
labels <- format(as.POSIXct(tck, origin="1970-01-01"), "%b %d")
text(tck, par("usr")[3], labels=labels, srt=315,
     xpd=TRUE, adj=c(-0.2,1.2), cex=0.9)

关于r - 在x轴上绘制R中的旋转标签,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/18766631/

10-10 18:03