多面ggplot中的ggstatsplot字幕输出
ggstatsplot subtitle output in faceted ggplot
我正在尝试将 grouped_ggbetweenstats() 的输出添加到多面 ggplot。这个说不可能,但是感觉回答者没看懂问题
group_ggbetweenstats() 有一个选项 output = "subtitle" 不是生成图,而是生成字符串表示将由 grDevices::mtext() 解释的统计测试的输出。然后可以将该文本作为标签提供给您要面对的因素。唯一似乎缺少的部分是 grDevices 的评估。
示例如下:
library(ggplot2)
library(ggstatsplot)
mtcars1 <- mtcars
statistics <- grouped_ggbetweenstats(data = mtcars1, x = cyl, y = mpg, grouping.var = am, output = "subtitle")
mtcars1$am <- factor(mtcars1$am, levels = c(0,1), labels = statistics)
mtcars1 %>%
ggplot(aes(x = cyl, y = mpg)) +
geom_jitter() +
facet_wrap(vars(am), ncol =1, strip.position = "top")
这给出:
而我们想要的是看起来像这样的东西(多面除外):
所以问题是:
- 是否可以获取分面标签来解释 mtext() 指令 OR
- 是否可以在绘图环境之外解释 mtext() 指令,然后将此解释的文本作为标签传递给 facet_wrap/grid OR
- 是否可以在与标签分开的方面包含副标题(就像 stat_compare_mean 那样)OR
- 其他...
您只需要解析构面标签中的那些表达式,这应该可以做到:
set.seed(123)
library(ggplot2)
library(ggstatsplot)
# data
mtcars1 <- mtcars
statistics <- grouped_ggbetweenstats(data = mtcars1, x = cyl, y = mpg, grouping.var = am, output = "subtitle")
mtcars1$am <- factor(mtcars1$am, levels = c(0,1), labels = statistics)
# plot
mtcars1 %>%
ggplot(aes(x = cyl, y = mpg)) +
geom_jitter() +
facet_wrap(vars(am), ncol =1, strip.position = "top", labeller = ggplot2::label_parsed)
由 reprex package (v0.3.0)
于 2020 年 7 月 18 日创建
我正在尝试将 grouped_ggbetweenstats() 的输出添加到多面 ggplot。这个
group_ggbetweenstats() 有一个选项 output = "subtitle" 不是生成图,而是生成字符串表示将由 grDevices::mtext() 解释的统计测试的输出。然后可以将该文本作为标签提供给您要面对的因素。唯一似乎缺少的部分是 grDevices 的评估。
示例如下:
library(ggplot2)
library(ggstatsplot)
mtcars1 <- mtcars
statistics <- grouped_ggbetweenstats(data = mtcars1, x = cyl, y = mpg, grouping.var = am, output = "subtitle")
mtcars1$am <- factor(mtcars1$am, levels = c(0,1), labels = statistics)
mtcars1 %>%
ggplot(aes(x = cyl, y = mpg)) +
geom_jitter() +
facet_wrap(vars(am), ncol =1, strip.position = "top")
这给出:
而我们想要的是看起来像这样的东西(多面除外):
所以问题是:
- 是否可以获取分面标签来解释 mtext() 指令 OR
- 是否可以在绘图环境之外解释 mtext() 指令,然后将此解释的文本作为标签传递给 facet_wrap/grid OR
- 是否可以在与标签分开的方面包含副标题(就像 stat_compare_mean 那样)OR
- 其他...
您只需要解析构面标签中的那些表达式,这应该可以做到:
set.seed(123)
library(ggplot2)
library(ggstatsplot)
# data
mtcars1 <- mtcars
statistics <- grouped_ggbetweenstats(data = mtcars1, x = cyl, y = mpg, grouping.var = am, output = "subtitle")
mtcars1$am <- factor(mtcars1$am, levels = c(0,1), labels = statistics)
# plot
mtcars1 %>%
ggplot(aes(x = cyl, y = mpg)) +
geom_jitter() +
facet_wrap(vars(am), ncol =1, strip.position = "top", labeller = ggplot2::label_parsed)
由 reprex package (v0.3.0)
于 2020 年 7 月 18 日创建