问题
This question refers to, and requires (but maybe not?), the function facet_wrap_labeller
written by Roland here: https://stackoverflow.com/a/16964861/3275826
MWE for my case:
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)
Problem: Facet strip labels are non-trivial to manipulate when using facet_wrap. In my case the plot shows K[12:3] etc rather than the [12:3] as a subscript as I would like.
I like Roland's function but I don't know how to adapt it for the case where your label subscripts are not just integers. A solution can be found at https://stackoverflow.com/a/6539953/3275826 however I would like to know how to adapt the aforementioned function as I have a lot of these instances.
Someone who is more confident than me with "computing on the language" could help, but perhaps I am overcomplicating the problem? Using R 3.0.2
and ggplot2_0.9.3.1
.
来源:https://stackoverflow.com/questions/25292524/ggplot2-how-to-use-facet-wrap-labeller-to-get-correct-subscripts