2014-01-24 114 views
1
x<- structure(list(count = c(4259120, 4317840, 4444000, 4254240, 
4656800), the_date = structure(c(1389589200, 1389675600, 1389762000, 
1389848400, 1389934800), class = c("POSIXct", "POSIXt"), tzone = "")), .Names =  c("count", 
"the_date"), row.names = c(51L, 406L, 664L, 197L, 196L), class = "data.frame") 

par(mar = c(8, 4, 4, 2) + 0.1) 
plot(x$the_date, x$count, type="l", xaxt = "n", xlab = "") 
axis(1, labels = FALSE) 
labels<-x$the_date 
labels<-format(labels, format="%b-%d-%Y") 
text(x$the_date, par("usr")[3] - 0.75, srt = 55, adj = 1, labels = labels, xpd = TRUE) 

我试过调整par("usr")[3] - 0.75偏移量,如指定的here,但标签根本没有移动。从x轴向下移动x轴标签

回答

1

你可以像这样使用2个调用axis函数的技巧。我在这里使用axis.Date,因为你处理日期(更好的格式)。然后你可以用line自变量与标签位置一起玩。

axis(1,labels=FALSE) 
axis.Date(1,at = x$the_date,las=2, format= "%m-%d",line=0.5,tick=FALSE) 

enter image description here

+0

任何方式让他们在一定程度上,而不是仅仅旋转90度? – tcash21

+0

@ tcash21可以更好地移动到更高点的图库上。比如'ggplot2'或'lattice'。 – agstudy

+0

是的,我想通了。我会回到'ggplot2'。谢谢! – tcash21