我无法使用ggplot2在每个方面内绘制排序值。
以下是示例图
ggplot(data=df) +
geom_point(aes(y=log(count_neg,10), x= ref_name, colour=replicate)) +
facet_grid(condition ~ sub_groups)
我想要做的是按Y值对每个方面的点进行排序。我尝试了以下但是没有用:
ggplot(data=df) +
geom_point(aes(sort(y=log(count_neg,10),decreading=TRUE),
x= ref_name, colour=replicate)) +
facet_grid(condition ~ sub_groups)
原始数据:
df<-structure(list(condition = structure(c(1L, 1L, 1L, 1L, 1L, 1L,
1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L,
1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L,
1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L,
1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L,
1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L,
1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L,
1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L,
1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L,
1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L,
1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L,
1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L,
1L, 1L), .Label = c("N_0m", "N_10m", "N_1h", "N_24h", "N_2h",
"N_30m", "N_48h", "N_6h", "N_8h"), class = "factor"), replicate = structure(c(1L,
1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L,
1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L,
1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L,
1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L,
1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L,
1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 2L, 2L, 2L, 2L, 2L,
2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L,
2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L,
2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L,
2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L,
2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L,
2L, 2L, 2L, 2L, 2L, 2L, 2L), .Label = c("A", "B"), class = "factor"),
ref_name = structure(c(1L, 2L, 3L, 4L, 5L, 6L, 7L, 8L, 9L,
10L, 11L, 12L, 13L, 14L, 15L, 16L, 17L, 18L, 19L, 20L, 21L,
22L, 23L, 24L, 25L, 26L, 27L, 28L, 29L, 30L, 31L, 32L, 33L,
34L, 35L, 36L, 37L, 38L, 39L, 40L, 41L, 42L, 43L, 44L, 45L,
46L, 47L, 48L, 49L, 50L, 51L, 52L, 53L, 54L, 55L, 56L, 57L,
58L, 59L, 60L, 61L, 62L, 63L, 64L, 65L, 66L, 67L, 68L, 69L,
70L, 71L, 72L, 73L, 74L, 75L, 76L, 77L, 78L, 79L, 80L, 81L,
82L, 83L, 84L, 85L, 86L, 87L, 88L, 89L, 90L, 91L, 92L, 1L,
2L, 3L, 4L, 5L, 6L, 7L, 8L, 9L, 10L, 11L, 12L, 13L, 14L,
15L, 16L, 17L, 18L, 19L, 20L, 21L, 22L, 23L, 24L, 25L, 26L,
27L, 28L, 29L, 30L, 31L, 32L, 33L, 34L, 35L, 36L, 37L, 38L,
39L, 40L, 41L, 42L, 43L, 44L, 45L, 46L, 47L, 48L, 49L, 50L,
51L, 52L, 53L, 54L, 55L, 56L, 57L, 58L, 59L, 60L, 61L, 62L,
63L, 64L, 65L, 66L, 67L, 68L, 69L, 70L, 71L, 72L, 73L, 74L,
75L, 76L, 77L, 78L, 79L, 80L, 81L, 82L, 83L, 84L, 85L, 86L,
87L, 88L, 89L, 90L, 91L, 92L), .Label = c("ERCC-00002", "ERCC-00003",
"ERCC-00004", "ERCC-00009", "ERCC-00012", "ERCC-00013", "ERCC-00014",
"ERCC-00016", "ERCC-00017", "ERCC-00019", "ERCC-00022", "ERCC-00024",
"ERCC-00025", "ERCC-00028", "ERCC-00031", "ERCC-00033", "ERCC-00034",
"ERCC-00035", "ERCC-00039", "ERCC-00040", "ERCC-00041", "ERCC-00042",
"ERCC-00043", "ERCC-00044", "ERCC-00046", "ERCC-00048", "ERCC-00051",
"ERCC-00053", "ERCC-00054", "ERCC-00057", "ERCC-00058", "ERCC-00059",
"ERCC-00060", "ERCC-00061", "ERCC-00062", "ERCC-00067", "ERCC-00069",
"ERCC-00071", "ERCC-00073", "ERCC-00074", "ERCC-00075", "ERCC-00076",
"ERCC-00077", "ERCC-00078", "ERCC-00079", "ERCC-00081", "ERCC-00083",
"ERCC-00084", "ERCC-00085", "ERCC-00086", "ERCC-00092", "ERCC-00095",
"ERCC-00096", "ERCC-00097", "ERCC-00098", "ERCC-00099", "ERCC-00104",
"ERCC-00108", "ERCC-00109", "ERCC-00111", "ERCC-00112", "ERCC-00113",
"ERCC-00116", "ERCC-00117", "ERCC-00120", "ERCC-00123", "ERCC-00126",
"ERCC-00130", "ERCC-00131", "ERCC-00134", "ERCC-00136", "ERCC-00137",
"ERCC-00138", "ERCC-00142", "ERCC-00143", "ERCC-00144", "ERCC-00145",
"ERCC-00147", "ERCC-00148", "ERCC-00150", "ERCC-00154", "ERCC-00156",
"ERCC-00157", "ERCC-00158", "ERCC-00160", "ERCC-00162", "ERCC-00163",
"ERCC-00164", "ERCC-00165", "ERCC-00168", "ERCC-00170", "ERCC-00171"
), class = "factor"), count_neg = c(468869L, 34677L, 113226L,
23508L, 8655L, 9319L, 210L, 25675L, 928L, 53981L, 8878L,
22507L, 5880L, 11756L, 21688L, 95L, 2397L, 6553L, 2533L,
12714L, 110L, 13520L, 71598L, 3177L, 55453L, 4157L, 3391L,
2740L, 144203L, 52L, 10710L, 15576L, 22028L, 5328L, 42474L,
1906L, 2829L, 12753L, 1207L, 351477L, 28401L, 5523L, 1166L,
7515L, 2773L, 17744L, 757L, 16316L, 16855L, 1236L, 16087L,
5447L, 358290L, 29127L, 34571L, 159457L, 630L, 46067L, 5977L,
22835L, 4014L, 111972L, 12372L, 5396L, 8183L, 1293L, 210L,
734814L, 10174L, 12838L, 39742L, 4259L, 35927L, 801L, 16309L,
16153L, 133685L, 8209L, 4331L, 5319L, 6029L, 3074L, 4768L,
2274L, 4958L, 9128L, 7243L, 2946L, 14718L, 20577L, 11257L,
78889L, 2407687L, 116262L, 52712L, 47998L, 10892L, 10124L,
479L, 19437L, 1257L, 61059L, 31119L, 25751L, 10645L, 14689L,
20248L, 92L, 3168L, 11003L, 3396L, 16732L, 176L, 29809L,
77936L, 12340L, 155159L, 5336L, 3818L, 3127L, 163497L, 66L,
14612L, 12687L, 25586L, 6996L, 25554L, 2284L, 3667L, 15745L,
1444L, 1033128L, 20087L, 17619L, 1412L, 11946L, 8014L, 19551L,
978L, 24182L, 22125L, 1717L, 14514L, 4564L, 903132L, 33653L,
39776L, 173518L, 796L, 35684L, 6524L, 62638L, 14418L, 398893L,
7938L, 6422L, 10595L, 1563L, 572L, 370134L, 10825L, 13837L,
17794L, 5164L, 43831L, 1114L, 17244L, 18924L, 171171L, 10228L,
5789L, 6847L, 6467L, 3582L, 6834L, 3084L, 7450L, 12474L,
6399L, 2390L, 22084L, 20090L, 7961L, 192521L), sub_groups = structure(c(4L,
4L, 1L, 2L, 3L, 4L, 4L, 3L, 1L, 1L, 4L, 3L, 2L, 1L, 2L, 1L,
2L, 2L, 3L, 3L, 4L, 2L, 4L, 3L, 4L, 4L, 2L, 2L, 3L, 3L, 3L,
4L, 2L, 4L, 1L, 2L, 4L, 3L, 2L, 3L, 2L, 3L, 4L, 4L, 4L, 4L,
1L, 3L, 1L, 4L, 1L, 1L, 2L, 1L, 3L, 3L, 2L, 1L, 2L, 3L, 4L,
3L, 1L, 2L, 3L, 1L, 2L, 1L, 1L, 1L, 1L, 4L, 2L, 2L, 3L, 1L,
3L, 1L, 2L, 2L, 1L, 1L, 3L, 2L, 4L, 3L, 4L, 3L, 4L, 4L, 1L,
2L, 4L, 4L, 1L, 2L, 3L, 4L, 4L, 3L, 1L, 1L, 4L, 3L, 2L, 1L,
2L, 1L, 2L, 2L, 3L, 3L, 4L, 2L, 4L, 3L, 4L, 4L, 2L, 2L, 3L,
3L, 3L, 4L, 2L, 4L, 1L, 2L, 4L, 3L, 2L, 3L, 2L, 3L, 4L, 4L,
4L, 4L, 1L, 3L, 1L, 4L, 1L, 1L, 2L, 1L, 3L, 3L, 2L, 1L, 2L,
3L, 4L, 3L, 1L, 2L, 3L, 1L, 2L, 1L, 1L, 1L, 1L, 4L, 2L, 2L,
3L, 1L, 3L, 1L, 2L, 2L, 1L, 1L, 3L, 2L, 4L, 3L, 4L, 3L, 4L,
4L, 1L, 2L), .Label = c("A", "B", "C", "D"), class = "factor")), .Names = c("condition",
"replicate", "ref_name", "count_neg", "sub_groups"), row.names = c(NA,
184L), class = "data.frame")
答案 0 :(得分:4)
试试这个:
df$ref_name <- reorder(df$ref_name,-log(df$count_neg,10))
ggplot(data=df) +
geom_point(aes(y=log(count_neg,10), x= ref_name, colour=replicate)) +
facet_grid(condition ~ sub_groups)
如果你想要相反的顺序,请或省略减号。这将x轴按(全局)y值排序。如果你打算单独订购每个方面,这有点复杂,部分原因是它使图表更加混乱。