, 당신은 임의의 텍스트를 포장하기 위해 labeller
인수의 기능을 사용할 수 있습니다. (facet_wrap
이 labeller
인수가 (yet)하지 않습니다.)
레이블을 래핑하는
x
재현
x <-
structure(list(Date = structure(c(-719143, -718778), class = "Date"),
Duration = c(10L, 3L), Test = c("This is the first that took place on1/1/2012",
"This test peformed the best result")), .Names = c("Date",
"Duration", "Test"), row.names = c(NA, -2L), class = "data.frame")
도우미 기능을 확인
library("plyr")
label_wrap_gen <- function(width = 25) {
function(variable, value) {
laply(strwrap(as.character(value), width=width, simplify=FALSE),
paste, collapse="\n")
}
}
플로팅 코드 (자세한 내용 on the ggplot2 wiki에서 논의). 단지 두 개의 값이 주어지기 때문에 점으로 변경되었으므로 선과 다듬기가 의미가 없습니다. 그러나 그것들은 어쨌든 질문의 초점이 아니 었습니다.
ggplot(x, aes(Date, Duration, group=Test, colour=Test)) +
geom_point() +
facet_grid(~Test, scale="free", labeller=label_wrap_gen(width=10)) +
opts(strip.text.x = theme_text(size=8, colour="navyblue"))
편집 : 당신을 위해 작동하지 않습니다
facet_grid
때문에, 직접 Test
변수로 줄 바꿈을 포함하고 facet_wrap
을 사용할 수 있습니다.
x$Test <- laply(strwrap(as.character(x$Test), width=10, simplify=FALSE),
paste, collapse="\n")
ggplot(x, aes(Date, Duration, group=Test, colour=Test)) +
geom_point() +
facet_wrap(~Test, scale="free") +
opts(strip.text.x = theme_text(size=8, colour="navyblue"))
내가 코멘트에서 만든 헤더에 대한 다른 질문을 이해하지 않습니다. 아마도 새롭고 명확한 질문을 던지십시오.
그리드가 더 많으므로이 점이 저에게 효과적입니다. 이것은 잘 알고 있습니다. – user1471980
헤더 표시와 관련하여 다른 질문이 있습니다. y-axix의 오른쪽 위와 오른쪽에 텍스트를 넣으려면 어떻게해야합니까? 이제 y 축에 날짜가 있고 그래프 상단에 테스트가 있습니다. 나는 90도 천사의 y 축척 오른쪽에 다른 표제를 넣고 싶다. – user1471980