label_bquote() 不适用于 ggplot2 中的列分面
label_bquote() doesn't work with column faceting in ggplot2
虽然我已经能够让 label_bquote()
与 geom_raster()
一起工作,当分面成行时,它似乎在分面成列时不起作用。这是一个可重现的示例,其中栅格被分面成行,给出正确的输出:
library(ggplot2)
d = expand.grid(
X = c(1, 2, 3),
Y = c(1, 2, 3),
Z = c(1, 2, 3)
)
set.seed(123)
d$A = runif(27)
p = ggplot(
data = d
) +
geom_raster(
mapping = aes(
x = X,
y = Y,
fill = A
)
) + facet_grid(
Z ~ .,
labeller = label_bquote(
"Z Value ="~ .(Z)
)
)
输出如您所料:
但是,如果 facet_grid()
公式更改为显示列而不是行:
) + facet_grid(
. ~ Z,
labeller = label_bquote(
"Z Value ="~ .(Z)
)
)
然后忽略bquote标签,只使用parsed标签:
请问这是什么原因造成的?
编辑:我应该补充说:我正在使用来自 CRAN 的 ggplot2 版本 3.1.0。
我将其报告为错误,但显然不是...请参阅 this issue。
label_bquote() has both rows and cols arguments! You'll need to specify which is which to get it working with facet_grid().
或在 ggplot2 manual:
label_bquote(rows = NULL, cols = NULL, default)
虽然我已经能够让 label_bquote()
与 geom_raster()
一起工作,当分面成行时,它似乎在分面成列时不起作用。这是一个可重现的示例,其中栅格被分面成行,给出正确的输出:
library(ggplot2)
d = expand.grid(
X = c(1, 2, 3),
Y = c(1, 2, 3),
Z = c(1, 2, 3)
)
set.seed(123)
d$A = runif(27)
p = ggplot(
data = d
) +
geom_raster(
mapping = aes(
x = X,
y = Y,
fill = A
)
) + facet_grid(
Z ~ .,
labeller = label_bquote(
"Z Value ="~ .(Z)
)
)
输出如您所料:
但是,如果 facet_grid()
公式更改为显示列而不是行:
) + facet_grid(
. ~ Z,
labeller = label_bquote(
"Z Value ="~ .(Z)
)
)
然后忽略bquote标签,只使用parsed标签:
请问这是什么原因造成的?
编辑:我应该补充说:我正在使用来自 CRAN 的 ggplot2 版本 3.1.0。
我将其报告为错误,但显然不是...请参阅 this issue。
label_bquote() has both rows and cols arguments! You'll need to specify which is which to get it working with facet_grid().
或在 ggplot2 manual:
label_bquote(rows = NULL, cols = NULL, default)