美文网首页
02坐标轴以科学计数法显示

02坐标轴以科学计数法显示

作者: Jachin111 | 来源:发表于2022-12-06 21:53 被阅读0次

构造一份数据

df <- data.frame(x=c("A","B","C","D"),
                 y=c(0.001,0.002,0.003,0.004))
df

最基本的柱形图

library(ggplot2)
ggplot(df,aes(x=x,y=y)) + geom_col()
image.png

科学计数法1

ggplot(df,aes(x=x,y=y)) +
  geom_col() +
  scale_y_continuous(labels=scales::scientific)
image.png

科学计数法2

ggplot(df,aes(x=x,y=y)) +
  geom_col() +
  scale_y_continuous(labels=c(expression(italic(0)),
                              expression(1%*%10^-10),
                              expression(2%*%10^-10),
                              expression(3%*%10^-10),
                              expression(4%*%10^-10)),
                     # position="right",
                     expand=c(0,0),
                     breaks=c(0,0.001,0.002,0.003,0.004),
                     limits=c(0,0.005))
image.png

图片横置

ggplot(df,aes(x=x,y=y)) +
  geom_col() +
  scale_y_continuous(labels=c(expression(italic(0)),
                              expression(1%*%10^-10),
                              expression(2%*%10^-10),
                              expression(3%*%10^-10),
                              expression(4%*%10^-10)),
                     position="right",
                     expand=c(0,0),
                     breaks=c(0,0.001,0.002,0.003,0.004),
                     limits=c(0,0.005)) +
  labs(y=NULL) +
  coord_flip() +
  theme_bw()
image.png

相关文章

网友评论

      本文标题:02坐标轴以科学计数法显示

      本文链接:https://www.haomeiwen.com/subject/maygfdtx.html