如何使 R 中的 ggplot 中的 y 尺度遵循类似的编号格式?

How to make y-scales in ggplot in R follow similar numbering format?

我想更改 y-axis 数字的格式,以便 axis-es 遵循类似的编号格式。现在 Facet A 是简单的,而 Facet B 是科学的。我知道这两个 facets 的值有很大差异,这就是为什么我使用 log scale 使低值更明显。我用 labels = "scientific" 来强制比例是科学的,但给我错误。这是我的代码 - 任何帮助将不胜感激。

library(tidyverse)

DF = data.frame(A = runif(8000, 100,800), B = runif(8000, 0, 10), C = 1:8000)
DF_g = gather(DF, key = "Variable", value = "Value", - C)
ggplot(DF_g, aes(x = C, y = Value, color = Variable))+
  geom_boxplot(lwd = 1)+facet_wrap(~Variable, nrow = 2, scales = "free_y")+
  scale_y_continuous(trans = "log10")

我从代码中得到的图是

您可以使用 scales 中的函数 scientific_format():

ggplot(DF_g, aes(x = C, y = Value, color = Variable))+
    geom_boxplot(lwd = 1)+facet_wrap(~Variable, nrow = 2, scales = "free_y")+
    scale_y_continuous(trans = "log10", labels = scales::scientific_format())