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 6L,
6L, 6L, 6L, 6L, 6L, 6L, 6L, 6L, 6L, 6L, 6L, 6L, 6L, 6L, 6L, 6L,
6L, 6L, 6L, 6L, 6L, 6L, 6L, 6L, 6L, 6L, 6L, 6L, 6L, 6L, 6L, 6L,
6L, 6L, 6L, 6L, 6L, 6L, 6L), values = c(13, 22, 16, 21, 52, 1,
1.709, 2.121, 2.061, 2.233, 3.388, 1, 5, 6, 6, 2, 1, 0.856, 1.116,
1.207, 1.175, 0.95, 76, 45, 5, 1, 1, 15, 8.558, 5.44, 1.147,
0.857, 0.831, 10, 7, 40, 4, 10, 5, 1.547, 1.174, 4.777, 1.071,
1.356, 7, 0, 1, 6, 1, 8, 1.322, 0.728, 0.83, 1.178, 0.831, 4,
2, 0, 1, 3, 0, 1.098, 0.96, 0.63, 0.888, 1.013, 13, 22, 16, 21,
52, 1, 1.709, 2.121, 2.061, 2.233, 3.388, 3, 6, 7, 2, 9, 11,
0.952, 1.474, 1.45, 0.967, 1.306, 13, 22, 16, 21, 52, 1, 1.709,
2.121, 2.061, 2.233, 3.388, 3, 8, 15, 0, 5, 2, 1.014, 1.583,
2.289, 0.773, 1.135, 10, 3, 8, 1, 4, 2, 1.504, 1.03, 1.244, 0.884,
1.047, 4, 1, 0, 2, 5, 1, 1.066, 0.862, 0.689, 0.963, 1.125, 2,
0, 0, 2, 0, 1, 0.919, 0.723, 0.479, 0.922, 0.721, 7, 8, 0, 8,
7, 0, 1.299, 1.236, 0.779, 1.298, 1.224, 13, 22, 16, 21, 52,
1, 1.709, 2.121, 2.061, 2.233, 3.388, 45, 38, 41, 13, 34, 1,
2.817, 2.264, 2.398, 1.374, 3.848, 3, 0, 1, 1, 2, 14, 0.973,
0.641, 0.846, 0.866, 0.909, 13, 22, 16, 21, 52, 1, 1.709, 2.121,
2.061, 2.233, 3.388, 7, 0, 0, 1, 2, 1, 1.37, 0.436, 0.706, 0.685,
0.902, 0, 5, 5, 0, 7, 1, 0.597, 1.113, 1.079, 0.71, 1.222, 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, 5L, 5L, 5L, 5L, 5L, 5L, 5L, 5L,
5L, 5L, 5L, 5L, 5L, 5L, 5L, 5L, 5L, 5L, 5L, 5L, 5L, 5L, 5L,
5L, 6L, 6L, 6L, 6L, 6L, 6L, 6L, 6L, 6L, 6L, 6L, 6L, 6L, 6L,
6L, 6L, 6L, 6L, 6L, 6L, 6L, 6L, 6L, 6L, 6L, 6L, 6L, 6L, 6L,
6L, 6L, 6L, 6L, 6L, 6L, 6L, 6L, 6L, 6L, 6L, 6L, 6L, 6L, 6L
), .Label = c("D<U+2192>", "G<U+2192>", "A<U+2192>", "K<U+2192>",
"C<U+2192>", "T<U+2192>"), class = "factor")), .Names = c("base",
"pos", "values", "type", "labels"), row.names = c("1", "2", "3",
"4", "5", "3942", "3943", "3944", "3945", "3946", "3947", "11",
"21", "31", "41", "51", "63", "64", "65", "66", "67", "68", "12",
"22", "32", "42", "52", "2953", "2954", "2955", "2956", "2957",
"2958", "13", "23", "33", "43", "53", "2461", "2462", "2463",
"2464", "2465", "2466", "14", "24", "34", "44", "54", "7493",
"7494", "7495", "7496", "7497", "7498", "111", "214", "311",
"411", "511", "4874", "4875", "4876", "4877", "4878", "4879",
"121", "221", "321", "421", "521", "9356", "9357", "9358", "9359",
"9360", "9361", "131", "231", "331", "431", "531", "9221", "9222",
"9223", "9224", "9225", "9226", "15", "25", "35", "45", "55",
"93561", "93571", "93581", "93591", "93601", "93611", "112",
"215", "312", "412", "512", "1579", "1580", "1581", "1582", "1583",
"1584", "122", "222", "322", "422", "522", "1782", "1783", "1784",
"1785", "1786", "1787", "132", "232", "332", "432", "532", "3398",
"3399", "3400", "3401", "3402", "3403", "16", "26", "36", "46",
"56", "2257", "2258", "2259", "2260", "2261", "2262", "113",
"216", "313", "413", "513", "1027", "1028", "1029", "1030", "1031",
"1032", "123", "223", "323", "423", "523", "8654", "8655", "8656",
"8657", "8658", "8659", "133", "233", "333", "433", "539", "702",
"703", "704", "705", "706", "707", "17", "27", "37", "47", "57",
"8123", "8124", "8125", "8126", "8127", "8128", "114", "217",
"314", "414", "514", "93562", "93572", "93582", "93592", "93602",
"93612", "124", "224", "324", "424", "524", "3700", "3701", "3702",
"3703", "3704", "3705", "134", "234", "334", "434", "5310", "8233",
"8234", "8235", "8236", "8237", "8238", "18", "28", "38", "48",
"58", "1542", "1543", "1544", "1545", "1546", "1547", "115",
"218", "315", "415", "515", "533", "534", "535", "536", "537",
"538", "125", "225", "325", "425", "525", "208", "209", "210",
"211", "212", "213", "135", "235", "335", "435", "5311", "93563",
"93573", "93583", "93593", "93603", "93613"), class = "data.frame")
这是dataw
head(dataw)
base pos values type labels
1 A 1 13 score D<U+2192>
2 A 1 22 score D<U+2192>
3 A 1 16 score D<U+2192>
4 A 1 21 score D<U+2192>
5 A 1 52 score D<U+2192>
3942 A 1 1 score D<U+2192>
我正在密谋它。
prettify <- theme(panel.background = element_rect(fill = NA,color="gray"),
panel.grid.major.y = element_blank(),
panel.grid.major.x = element_line(size=.1, color="black",linetype="dotted"),
panel.grid.minor.y = element_blank(),
panel.grid.minor.x = element_line(size=.1, color="black"),
legend.position="bottom")
ggplot(dataw,aes(x = base, y = values, color = type, group = base)) +
geom_boxplot() +
facet_wrap(type ~ pos, scales="free_y", nrow = 2) +
theme_gray() %+replace% prettify
目前,子标签是type
值,后跟逗号和pos
值。但是我想摆脱类型值,并标记它,以便每个子图的标签格式为:“Position [pos value],[labels value]”
最好的方法是什么?谢谢。