是否有一种方法可以使用ggplot2在R中以科学符号显示绘图几何图形文本数据标签?

是否有一种方法可以使用ggplot2在R中以科学符号显示绘图几何图形文本数据标签?,r,ggplot2,geom-bar,scientific-notation,geom-text,R,Ggplot2,Geom Bar,Scientific Notation,Geom Text,我想用科学记数法显示绘图标签。通过将变量('TotVol')包装到函数中,这似乎是可能的,但是我还没有找到任何关于如何使用ggplot表示法进行绘图的建议 我的情节要求如下 p<-ggplot(data=df, aes(x=DayType, y=TotVol, fill = Year))+ geom_bar(stat="identity", position=position_dodge())+ geom_text(aes(label=TotVol),posit

我想用科学记数法显示绘图标签。通过将变量('TotVol')包装到函数中,这似乎是可能的,但是我还没有找到任何关于如何使用ggplot表示法进行绘图的建议

我的情节要求如下

p<-ggplot(data=df, aes(x=DayType, y=TotVol, fill = Year))+
  geom_bar(stat="identity", position=position_dodge())+
  geom_text(aes(label=TotVol),position=position_dodge(width=0.9), vjust = -0.25)

p如果我理解正确,您希望使用科学符号显示条顶部的标签。一种可能的做法是使用
formatC
调整格式:

library(ggplot2)                 
ggplot(data=df, aes(x=DayType, y=TotVol, fill = Year))+
  geom_bar(stat="identity", position=position_dodge())+
  geom_text(aes(label=formatC(TotVol, format = "e")),
            position=position_dodge(width=0.9), vjust = -0.25)

资料


df您是否尝试过
scales::scientific
df <- data.frame(DayType = c("a", "b", "a", "b"), TotVol=rep(200456567, 4), Year=c("1995", "1995", "2000", "2000") )