ggplot2:如何使用facet_wrap_labeller获取正确的下标

时间:2014-08-13 17:27:49

标签: r ggplot2 facet-wrap

这个问题是指并且要求(但可能不是?)罗兰在这里写的函数facet_wrap_labellerhttps://stackoverflow.com/a/16964861/3275826

我的案例的MWE:

dput(test)
structure(list(V1 = c(0.1, 0.3, 0.5, 0.7, 0.9, 1.1, 3.67, 3.73, 
3.79, 3.85, 3.91, 3.97), V2 = c(0.0291598, 3.40333, 1.3881, 0.15733, 
0.0200618, 0.00145373, 0.332262, 0.30233, 0.288497, 0.267876, 
0.264134, 0.227544), V3 = structure(c(1L, 1L, 1L, 1L, 1L, 1L, 
19L, 19L, 19L, 19L, 19L, 19L), .Label = c("Param0", "Param1", 
"Param2", "Param3", "Param4", "Param5", "Param6", "Param7", "Param8", 
"Param9", "Param10", "Param11", "Param12", "Param13", "Param14", 
"Param15", "Param16", "Param17", "Param18"), class = "factor")), .Names = c("V1", 
"V2", "V3"), row.names = c(1L, 2L, 3L, 4L, 5L, 6L, 945L, 946L, 
947L, 948L, 949L, 950L), class = "data.frame")

dput(testLabels)
structure(c(2L, 1L), .Label = c("K[12:3]", "K[12]"), class = "factor")

## Will shows Param0 in the strip but this is modified by the facet_wrap_labeller
pp = ggplot(test, aes(x=test$V1)) + geom_ribbon(aes(ymin=0,ymax=test$V2), fill="blue",  alpha=0.2, colour="blue") + facet_wrap(~V3, scales="free", ncol=3)
facet_wrap_labeller(pp, testLabels)

问题:使用facet_wrap时,小面条标签的操作非常简单。在我的例子中,情节显示K [12:3]等而不是[12:3]作为我想要的下标。

我喜欢Roland的功能,但我不知道如何适应标签下标不仅仅是整数的情况。 可以在https://stackoverflow.com/a/6539953/3275826找到解决方案但是我想知道如何调整上述功能,因为我有很多这样的实例。

有人比我更有信心"计算语言"可能有所帮助,但也许我的问题太复杂了?使用R 3.0.2ggplot2_0.9.3.1

0 个答案:

没有答案