내 R-plot에 콜 아웃 텍스트를 추가하고 싶습니다. 예를 들어, 나는 몇 가지 음모를 가지고 :R의 콜 아웃 텍스트
x <- seq(0, 2, by=0.1)
y <- x*x
plot(x, y, type="l")
I는 다음과 같이 몇 가지 설명 선 텍스트를 추가 할 : 그것은 몇 가지 표준 방법이
있다?
내 R-plot에 콜 아웃 텍스트를 추가하고 싶습니다. 예를 들어, 나는 몇 가지 음모를 가지고 :R의 콜 아웃 텍스트
x <- seq(0, 2, by=0.1)
y <- x*x
plot(x, y, type="l")
I는 다음과 같이 몇 가지 설명 선 텍스트를 추가 할 : 그것은 몇 가지 표준 방법이
있다?
?text
(및 ?arrows
)을 살펴보십시오.
x <- seq(0, 2, by=0.1)
y <- x*x
plot(x, y, type="l")
text(0.25, 2, "Some text", pos=3)
arrows(0.25, 2, 1, 1)
UPDATE :
당신은 작은 함수에 text
, lines
및 arrows
을 결합 할 수 있습니다 :
x <- seq(0, 2, by=0.1)
y <- x*x
plot(x, y, type="l")
# x0, y0: coordinates of text; see ?text
# x1, y1: coordinates to which the arrows are drawn; see ?arrows
# labels: text
# vOffset/hOffset: vertical/horizontal offset
callout <- function(x0, y0, x1, y1, labels, vOffset=0.25, hOffset=0.25) {
## fetch labels width/height
w <- strwidth(labels)
w2 <- w/2
h <- strheight(labels)
h2 <- h/2
## draw text
text(x0, y0, labels=labels)
## calulate arrow starting point/line end point
x01 <- x0+w2*(1+hOffset)
y01 <- y0-h2*(1+vOffset)
## draw horizontal lines
for (i in seq(along=x0)) {
lines(c(x0[i]-w2[i], x01[i]), c(y01[i], y01[i]))
}
## draw arrows
arrows(x0=x01, y0=y01, x1=x1, y1=y1)
}
callout(c(0.25, 0.25), c(2, 3), c(1, 1.5), c(1, 2.25),
c("Some text", "Some other text"))
을 0
정확히 재현 할 수 나는 또한 lines
을 사용합니다 :
x <- seq(0, 2, by=0.1)
y <- x*x
plot(x, y, type="l")
text(0.25,2.2,'Some text')
lines(c(0, 0.5,1), c(2 ,2,1),
lwd=3, col="grey")
arrows(0.5,2,1,1,
lwd=3, col="grey")