我试图让x轴标签分成两行。我还希望标签旋转45度。我怎样才能做到这一点?
到目前为止我所拥有的:
N <- 10
dnow <- data.frame(x=1:N, y=runif(N), labels=paste("This is observation ",1:N))
with(dnow, plot(x,y, xaxt="n", xlab=""))
atn <- seq(1,N,3)
axis(1, at=atn, labels=labels[atn])
这是我使用基本图形制作的(在我的ggplot2
天之前):
## data
N <- 10
dnow <- data.frame(x=1:N, y=runif(N), labels=paste("This is \nobservation ",1:N))
## make margins wide
par(mfrow=c(1,1), mar=c(10,10,6,4))
## plot without axix labels or ticks
with(dnow, plot(x,y, xaxt="n", xlab=""))
## the positions we ant to plot
atn <- seq(1,N,3)
## the label for these positions
lab <- dnow$labels[atn]
## plot the axis, but do not plot labels
axis(1, at=atn, labels=FALSE)
## plot labels
text(atn, ## x position
par("usr")[3]-.05, ## position of the low axis
srt=45, ## angle
labels=lab, ##labels
xpd=TRUE, ## allows plotting outside the region
pos=2)
## par("usr")[3]