我正在尝试使用label_bquote
标记网格中的行。
这是我到目前为止的内容:labeller = label_bquote(rows=mu=="1x10"^.(levels(Mut_Rate))
Mut_Rate的级别为:levels(all_summ$Mut_Rate)<-c("-4","-5","-6","-7","-8")
运行贴标签机时,我为行获取以下标签:
[]
这是为什么?我希望标签为mu = 1x10 ^ -4,-5,-6等。
我全力以赴以另一种方式做到这一点,但是我可以在其他地块上使用它,但我不知道为什么这不起作用。
使用mpg
数据集,我可以重新创建问题(某种程度上)。
p <- ggplot(mpg, aes(displ, cty)) + geom_point()
levels(mpg$drv)<-c("4","f","r",)
p + facet_grid(drv ~ cyl,labeller = label_bquote(rows=mu=="1x10" ^ .(levels(drv))))
我要去哪里错了?
编辑:这是我的数据子集的dput
:
structure(list(Mut_Rate = structure(c(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, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 4L,
4L, 4L, 4L, 4L, 4L, 4L, 4L, 4L, 4L, 4L, 4L, 5L, 5L, 5L, 5L, 5L,
5L, 5L, 5L, 5L, 5L, 5L, 5L, 5L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L,
1L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 3L, 3L, 3L, 3L, 3L,
3L, 3L, 3L, 3L, 3L, 4L, 4L, 4L, 4L, 4L, 4L, 4L, 4L, 4L, 4L, 5L,
5L, 5L, 5L, 5L, 5L, 5L, 5L, 5L, 5L), .Label = c("1e-08", "1e-07",
"1e-06", "1e-05", "1e-04"), class = "factor"), colors_here = structure(c(1L,
1L, 1L, 2L, 2L, 3L, 3L, 4L, 4L, 4L, 5L, 5L, 1L, 1L, 1L, 2L, 2L,
3L, 3L, 3L, 4L, 4L, 5L, 5L, 5L, 1L, 1L, 2L, 2L, 2L, 3L, 3L, 4L,
4L, 5L, 5L, 5L, 1L, 1L, 2L, 2L, 2L, 3L, 3L, 4L, 4L, 4L, 5L, 5L,
1L, 1L, 1L, 2L, 2L, 3L, 3L, 3L, 4L, 4L, 5L, 5L, 5L, 2L, 2L, 3L,
3L, 4L, 4L, 4L, 5L, 5L, 2L, 2L, 2L, 3L, 3L, 4L, 4L, 4L, 5L, 5L,
2L, 2L, 2L, 3L, 3L, 4L, 4L, 4L, 5L, 5L, 2L, 2L, 2L, 3L, 3L, 4L,
4L, 4L, 5L, 5L, 2L, 2L, 2L, 3L, 3L, 4L, 4L, 4L, 5L, 5L), .Label = c("100",
"500", "1000", "5000", "10000"), class = "factor"), x_values = c(1,
100, 2600, 28, 1450, 29, 1500, 6, 350, 2850, 33, 1700, 10, 550,
3050, 37, 1900, 14, 750, 6100, 41, 2100, 18, 950, 10100, 45,
2300, 22, 1150, 14100, 49, 2500, 26, 1350, 3, 200, 2700, 30,
1550, 7, 400, 2900, 34, 1750, 11, 600, 3100, 38, 1950, 15, 800,
7100, 42, 2150, 19, 1000, 11100, 46, 2350, 23, 1200, 15100, 49,
2500, 25, 1300, 1, 100, 2600, 27, 1400, 3, 200, 2700, 29, 1500,
5, 300, 2800, 31, 1600, 7, 400, 2900, 33, 1700, 9, 500, 3000,
35, 1800, 11, 600, 3100, 37, 1900, 13, 700, 5100, 39, 2000, 15,
800, 7100, 41, 2100, 17, 900, 9100, 43, 2200), y_values = c(0,
1.518e-06, 3.001e-06, 1.32e-07, 8.16e-06, 4.87e-07, 5.771e-06,
0, 3.086e-06, 2.5878e-05, 2.31e-07, 1.3455e-05, 0, 7.96875e-05,
3.09375e-06, 0, 9.746875e-05, 0, 0.00013453125, 0.00039434375,
6.1875e-06, 0.00017896875, 0, 0.000115, 0.0005994375, 6.68125e-05,
7.14375e-05, 1.2375e-05, 0.00071890625, 0.0008070625, 3.94375e-05,
0.0011611875, 1.95625e-05, 0.0011889375, 0, 0.00019146875, 0.002583875,
0.00018528125, 0.00210109375, 4.303125e-05, 0.003006375, 0.0080869375,
0.00034940625, 0.01132409375, 6.05e-05, 0.00564815625, 0.025672,
0.0003765, 0.01874928125, 0.00113753125, 0.0190550625, 0.016886125,
0.0040905, 0.07532540625, 0.00186221875, 0.07132434375, 0.14220003125,
0.00397665625, 0.16759309375, 0.0017900625, 0.10347159375, 0.39214809375,
1.111e-06, 7.506e-06, 3.307e-06, 1.8439e-05, 1.72e-06, 2.63e-06,
2.733e-05, 2.97e-07, 1.1348e-05, 1.621e-05, 4.4035e-05, 0.000104525,
1.084e-05, 0.0001369, 3.2165e-05, 6.376e-05, 0.000254345, 2.3765e-05,
0.00012591, 0.000294945, 0.000551865, 0.001035845, 0.000170355,
0.001156965, 0.00021164, 0.000689675, 0.002610485, 0.00026225,
0.002045535, 0.0021557, 0.0054404, 0.00898055, 0.0018754, 0.01137135,
0.00241075, 0.00888815, 0.04158005, 0.00230105, 0.0195085, 0.020169,
0.0575235, 0.0791955, 0.0199717, 0.1158792, 0.01812125, 0.09193755,
0.32251755, 0.02459615, 0.18119415), columns_here = c(2, 2, 2,
2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 100, 100,
100, 100, 100, 100, 100, 100, 100, 100, 100, 100, 100, 100, 100,
100, 100, 100, 100, 100, 100, 100, 100, 100, 100, 100, 100, 100,
100, 100, 100, 100, 100, 100, 100, 100, 100, 100, 100, 100, 100,
100, 100, 100, 100, 100, 100, 100, 100)), .Names = c("Mut_Rate",
"colors_here", "x_values", "y_values", "columns_here"), row.names = c(1L,
51L, 101L, 151L, 201L, 251L, 301L, 351L, 401L, 451L, 501L, 551L,
601L, 651L, 701L, 751L, 801L, 851L, 901L, 951L, 1001L, 1051L,
1101L, 1151L, 1201L, 1251L, 1301L, 1351L, 1401L, 1451L, 1501L,
1551L, 1601L, 1651L, 1701L, 1751L, 1801L, 1851L, 1901L, 1951L,
2001L, 2051L, 2101L, 2151L, 2201L, 2251L, 2301L, 2351L, 2401L,
2451L, 2501L, 2551L, 2601L, 2651L, 2701L, 2751L, 2801L, 2851L,
2901L, 2951L, 3001L, 3051L, 3101L, 3151L, 3201L, 3251L, 3301L,
3351L, 3401L, 3451L, 3501L, 3551L, 3601L, 3651L, 3701L, 3751L,
3801L, 3851L, 3901L, 3951L, 4001L, 4051L, 4101L, 4151L, 4201L,
4251L, 4301L, 4351L, 4401L, 4451L, 4501L, 4551L, 4601L, 4651L,
4701L, 4751L, 4801L, 4851L, 4901L, 4951L, 5001L, 5051L, 5101L,
5151L, 5201L, 5251L, 5301L, 5351L, 5401L, 5451L, 5501L), class = "data.frame")
这是我要绘制的代码:
q<-ggplot(for_stack,aes(x=x_values, y=y_values,color=colors_here))+
geom_point(data=for_stack,size=4)+
theme(text = element_text(size=18),legend.position = "bottom",strip.background = element_blank())
q+facet_grid(Mut_Rate~columns_here, scales="free_y", as.table = FALSE,labeller=label_bquote(rows = .(Mut_Rate),cols=N[e0]==.(columns_here)))+
theme(panel.background = element_rect(fill = NA, color = "black"),legend.key=element_blank())#The numbers look OK but no mu=
q<-ggplot(for_stack,aes(x=x_values, y=y_values,color=colors_here))+
geom_point(data=for_stack,size=4)+
theme(text = element_text(size=18),legend.position = "bottom",strip.background = element_blank())
q+facet_grid(Mut_Rate~columns_here, scales="free_y", as.table = FALSE,labeller=label_bquote(rows = mu== "1x10"^ .(Mut_Rate),cols=N[e0]==.(columns_here)))+
theme(panel.background = element_rect(fill = NA, color = "black"),legend.key=element_blank())#Looks great but the superscript numbers are incorrect. I need mu=1x10^-4, mu=1x10^-5, etc.
级别相同。
答案 0 :(得分:0)
很难说出原因,但这是导致问题的levels
。代替使用
label_bquote(rows = mu == "1x10" ^ .(drv))
完成工作。
编辑:问题是Mut_Rate
是一个因素。明确确保它是数字可解决此问题。在第一种情况下,您可以使用
mu == .(as.numeric(as.character(Mut_Rate)))
但我认为这不是所需的格式。在第二种情况下,我们可以拥有
mu== "1x10"^ .(log10(as.numeric(as.character(Mut_Rate))))
我相信看起来像预期的那样。