从x轴向下移动x轴标签

时间:2021-03-05 23:41:23
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)

I've tried adjusting the par("usr")[3] - 0.75 offset as specified here, but the labels aren't moving at all.

我已经尝试调整此处指定的par(“usr”)[3] - 0.75偏移量,但标签根本没有移动。

1 个解决方案

#1


1  

You can a trick like this using 2 calls to axis functions. I am using here axis.Date since you deal with dates(better for formatting). Then you can ply with line argument t play with labels positions.

你可以使用2次调用轴函数这样的技巧。我在这里使用axis.Date,因为你处理日期(更好的格式)。然后你可以使用行参数来播放标签位置。

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

从x轴向下移动x轴标签

#1


1  

You can a trick like this using 2 calls to axis functions. I am using here axis.Date since you deal with dates(better for formatting). Then you can ply with line argument t play with labels positions.

你可以使用2次调用轴函数这样的技巧。我在这里使用axis.Date,因为你处理日期(更好的格式)。然后你可以使用行参数来播放标签位置。

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

从x轴向下移动x轴标签