r - 将科学计数法 +e 转换为 geom_text 中带上标的 10^(y)

标签 r ggplot2 label expression

我想在每个栏的顶部添加数据标签。但我希望它不是 +e,而是 10^ 格式。 有很多关于斧头的文献。没有标签。 我的代码如下:

    amino.acids<-c(rep("Lysine",4),rep("Tryptophan",4),rep("Valine",4))
Source<-(rep(c("Cow","Cat","Monkey","Human"),3))
Values<-c(46846813,3186186135,6816135168,3178168,
          461351,681684351,3584684351,68463513511,
          8463510351,8435186468,1358486,6843513065)

df<-data.frame(Source,amino.acids,Values)

ggplot(df, aes(x=reorder(Source, -Values),y=Values, fill=Source))+
  geom_bar(stat = "identity", color="black")+
  facet_wrap(~amino.acids)+
  scale_y_log10(label = trans_format("log10",math_format(10^.x)))+
  xlab("")+ylab("Transformations Potential (Qu/Ha)")+
  theme(axis.text.x = element_text(angle = 45, hjust=1),
        legend.position = "none")

添加geom_text(label = trans_format("log10",math_format(10^.x)))失败。

最佳答案

您还需要在scale_y_log10中设置中断。

library(ggplot2)
library(scales)

ggplot(df, aes(x=reorder(Source, -Values),y=Values, fill=Source))+
  geom_bar(stat = "identity", color="black")+
  facet_wrap(~amino.acids)+
  scale_y_log10(breaks = trans_breaks("log10", function(x) 10^x), 
                labels = trans_format("log10", scales::math_format(10^.x)))+
  xlab("")+ylab("Transformations Potential (Qu/Ha)")+
  theme(axis.text.x = element_text(angle = 45, hjust=1),
        legend.position = "none")

enter image description here

关于r - 将科学计数法 +e 转换为 geom_text 中带上标的 10^(y),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/61749815/

相关文章:

ios - iOS 6 中的标签对齐 - 不推荐使用 UITextAlignment

r - 为 r 中的每个变量按组汇总表中的数据

r - 在构面的第一个情节中的位置图例

c++ - Qt在不使用线程时从不同的线程设置父级

r - ggplot2 中的嵌套 facet_wrap()

r - 将\in(是集合的成员)符号添加到qplot中

css - OpenERP( View ) - 随着标签和字段之间的空间变化?

r - 如何计算没有 NA 的中值?

r - 使用 NA 时向量长度不同

renv 0.12.0 是从项目库加载的,但 renv 0.11.0 记录在锁定文件中