, 나는 하지 당신이 보여주는 이미지를 얻는다.
text(axTicks(1), par("usr")[3] - 2, srt=45, adj=1, labels=lab, xpd=T, cex=0.8)
axTicks(1)
로 반환 :
> axTicks(1)
[1] 5 10 15
그래서 무슨 일이 일어나고 있는지 당신의 19 개 라벨 그 3 위치에 그려되고 있다는 것입니다 문제는이 라인입니다.
그런 다음 틱 (1:19
)의 위치에서 플롯하려면
:
text(1:19, par("usr")[3] - 2, srt=45, adj=1, labels=lab, xpd=T, cex=0.8)
작동합니다.
다음은 코드를 기반으로 한 전체 예제입니다.
Runtime <- c(579,0,581,610,830,828,592,651,596,596,591,581,587,
594,604,606,447,434,445)
g_range <- range(0,Runtime)
lab <- c('2011-07-20','2011-08-03','2011-08-10','2011-08-17','2011-08-24',
'2011-08-25','2011-08-27','2011-08-31','2011-09-07','2011-09-10',
'2011-09-14','2011-09-21','2011-09-28','2011-10-05','2011-10-06',
'2011-10-07','2011-10-13','2011-10-19','2011-10-31')
## plot
op <- par(mar = c(6,4,4,2) + 0.1) ## bigger bottom margin
plot(Runtime, type="o", col="blue", ylim=g_range, axes=FALSE, ann=FALSE)
box()
axis(1, at=1:19, lab=FALSE)
text(1:19, par("usr")[3] - 40, srt=45, adj=1.2, labels=lab, xpd=T, cex=0.7)
axis(2, las=1, at=500*0:g_range[2])
title(main="Runtime", col.main="red", font.main=4)
title(xlab="Build", col.lab=rgb(0,0.5,0), line = 4.5)
title(ylab="MS", col.lab=rgb(0,0.5,0))
legend("topright", c("AveElapsedTime"), cex=0.8, col=c("blue"), pch=21, lty=1)
## reset par
par(op)
이 더 잘 그리드 그래픽이 섞여하기 및 기반을 허용하는, 비록 gridBase 패키지의 기능을 사용하여 처리 될 수 있습니다. 내가 더 좋다고 말할 수있는 이유는 y
좌표가 플롯 된 데이터의 측면에서 y
에 적합한 값을 산출하려고 시도하는 것이 아니라 선의 개수로 설정되도록 지정할 수 있기 때문입니다. 이 화면에 약간 까다 롭고 될 수 있습니다 내 R 2.13.2에 gridBase 예를 어떤 라벨을 생성하지 않습니다 설치를 다시 실행
## load gridBase
require(gridBase)
## do the base plot parts
op <- par(mar = c(6,4,4,2) + 0.1) ## bigger bottom margin
plot(1:19, Runtime, type="o", col="blue", ylim=g_range, axes=FALSE, ann=FALSE)
box()
axis(1, at=1:19, lab=FALSE)
axis(2, las=1, at=500*0:g_range[2])
title(main="Runtime", col.main="red", font.main=4)
title(xlab="Build", col.lab=rgb(0,0.5,0), line = 4.5)
title(ylab="MS", col.lab=rgb(0,0.5,0))
legend("topright", c("AveElapsedTime"), cex=0.8, col=c("blue"), pch=21, lty=1)
## at this point, DO NOT alter the dimensions of the plotting window
## now do the grid business
vps <- baseViewports()
pushViewport(vps$inner, vps$figure, vps$plot)
## this adds the text
grid.text(lab, x = unit(1:19, "native"), y = unit(-1, "lines"),
just = "right", rot = 60, gp = gpar(cex = 0.7))
## this finishes off the viewport - you have to do this or things will go wrong:
popViewport(3)
## reset par
par(op)
참고 : 여기에
은 예입니다. 장치를 닫은 다음 코드를 새로 실행하면 문제가 해결됩니다. pdf()
기기로 그리는 경우 문제가 될 것이라고 생각하지 않습니다.
'las'를 사용하여 수직 또는 수평으로 만 이동할 수 있습니다. 각진 레이블을 원하면'text'를 사용하여 직접 작성해야합니다 : http://128.97.141.26/stat/R/faq/angled_labels.htm – James
@James err, OP * is *. 'srt'로'text()'호출을보십시오. –
코드를 스캔하고 축 호출 만 보았습니다. – James