gpt4 book ai didi

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

转载 作者:行者123 更新时间:2023-12-02 19:31:18 24 4
gpt4 key购买 nike

我想在每个栏的顶部添加数据标签。但我希望它不是 +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/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com