首页
学习
活动
专区
圈层
工具
发布
首页
学习
活动
专区
圈层
工具
MCP广场
社区首页 >问答首页 >更改ggplot中stat_compare_mean()输出的字体系列

更改ggplot中stat_compare_mean()输出的字体系列
EN

Stack Overflow用户
提问于 2020-04-09 22:25:40
回答 1查看 799关注 0票数 3

是否可以在下面的ggpboxplot中更改p值的字体系列?字体系列应为"Times New Roman“。

使用theme_bw(base_family = "Times New Roman")不会更改p值。

代码语言:javascript
运行
复制
library(ggpubr) 
library(ggplot2)
data("ToothGrowth")

# Box plot 
p <- ggboxplot(ToothGrowth, x = "supp", y = "len",
      color = "supp", palette = "jco",
      add = "jitter",
      facet.by = "dose", short.panel.labs = FALSE) 

p + stat_compare_means(label = "p.format")
p + theme_bw(base_family = "Times New Roman")

我也尝试了普通主题(text= ...)。它不起作用。

代码语言:javascript
运行
复制
# Box plot 
p <- ggboxplot(ToothGrowth, x = "supp", y = "len",
      color = "supp", palette = "jco",
      add = "jitter",
      facet.by = "dose", short.panel.labs = FALSE) 

p + stat_compare_means(label = "p.format")
p + theme(text = element_text(family = "Times New Roman"))

请注意:我取自以下网站的示例:https://rpkgs.datanovia.com/ggpubr/reference/stat_compare_means.html

非常,非常感谢!

万事如意,阿娜

EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2020-04-09 23:14:43

你很接近,family =参数直接在stat_compare_means()中使用。

来自help(stat_compare_means)

代码语言:javascript
运行
复制
Usage
stat_compare_means(mapping = NULL, data = NULL, method = NULL,
  paired = FALSE, method.args = list(), ref.group = NULL,
  comparisons = NULL, hide.ns = FALSE, label.sep = ", ",
  label = NULL, label.x.npc = "left", label.y.npc = "top",
  label.x = NULL, label.y = NULL, tip.length = 0.03,
  bracket.size = 0.3, step.increase = 0, symnum.args = list(),
  geom = "text", position = "identity", na.rm = FALSE,
  show.legend = NA, inherit.aes = TRUE, ...)
<snip>
...   other arguments to pass to geom_text or geom_label.

因此,这段代码应该可以做您想要做的事情。

代码语言:javascript
运行
复制
 ggboxplot(ToothGrowth, x = "supp", y = "len",
      color = "supp", palette = "jco",
      add = "jitter",
      facet.by = "dose", short.panel.labs = FALSE) +
      stat_compare_means(label = "p.format",family = "Times New Roman") 
      #Use this if on Windows:  stat_compare_means(label = "p.format",family = "TT Times New Roman")

票数 3
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/61123450

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档