如果可以使用facet_grid而不是facet_wrap,则可以使用labeller参数的功能来任意换行文本。(facet_wrap没有(还)有labeller论据。)
使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")
包装标签的辅助函数(在 ggplot2 wiki 上有更详细的讨论)
library("plyr")
label_wrap_gen <- function(width = 25) {
function(variable, value) {
laply(strwrap(as.character(value), width=width, simplify=FALSE),
paste, collapse="\n")
}
}
绘制代码。更改为点,因为只给出了两个值,所以线条和平滑没有意义。但无论如何,这些都不是问题的焦点。
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"))

我不明白你在评论中提出的关于标题的其他问题。也许从中提出一个新的、更清晰的问题。