1

我正在使用 R 包 GGPubr 来制作箱线图。我真的很喜欢它提供的漂亮视觉效果,但我遇到了问题。有谁知道如何增加轴上数字、轴标签和类标签的字体大小?另外,如何设置平均值以使它们仅显示 2 位小数?

这是我正在使用的代码:

library("ggpubr")
mydata <- read.csv("C:\\temp\\ndvi.csv")
ggboxplot(mydata, x = "class", y = "NDVI", 
      color = "class",
      order = c("Conifer", "Deciduous", "Grasslands"),  ggtheme=theme_gray(),
      ylab = "NDVI Value", xlab = "Land Cover Class",
      add="mean",
      font.label = list(size = 30, face = "bold"))+ stat_summary(fun.data 
= function(x) data.frame(y=1, label = paste("Mean=",mean(x))),  geom="text")
+theme(legend.position="none")

和 csv:

NDVI,class
0.25,Conifer
0.27,Conifer
0.29,Conifer
0.403,Deciduous
0.38,Deciduous
0.365,Deciduous
0.31983489,Grasslands
0.32005,Grasslands
0.328887766,Grasslands

我更愿意使用 GGPubr 而不是 boxplot() 或 ggplot/ggplot 2 来实现上述预期效果。谢谢。

4

1 回答 1

1

这是我们round()用来处理小数点后两位并添加另一个theme()以更改文本大小的选项。

ggboxplot(mydata, x = "class", y = "NDVI", 
          color = "class",
          order = c("Conifer", "Deciduous", "Grasslands"),  ggtheme=theme_gray(),
          ylab = "NDVI Value", xlab = "Land Cover Class",
          add="mean",
          font.label = list(size = 30, face = "bold")) +
  # use round() and set y = .45 
  stat_summary(fun.data = function(x) data.frame(y=1, label = paste("Mean=", round(mean(x), 2))), geom="text") + 
  theme(legend.position="none") +
  theme(text = element_text(size = 16)) # change text size of theme components

在此处输入图像描述

于 2019-02-04T18:24:55.233 回答