如何在ggplot中将轴值强制为科学计数法 [英] How to force axis values to scientific notation in ggplot

查看:170
本文介绍了如何在ggplot中将轴值强制为科学计数法的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有以下代码:

 library(ggplot2)
 df <- data.frame(y=seq(1, 1e5, length.out=100), x=sample(100))
 p  <- ggplot(data = df, aes(x=x, y=y)) + geom_line() + geom_point()
 p

产生这张图片的人

如上图所示,我该如何更改y轴值是否具有科学计数法?

As mentioned in the image above how can I change the y-axis value to scientific notation?

推荐答案

您可以在 scale_y_continuous标签参数上打开科学符号的情况下传递 format 函数:

You can pass a format function with scientific notation turned on to scale_y_continuous labels parameter:

p + scale_y_continuous(labels = function(x) format(x, scientific = TRUE))

这篇关于如何在ggplot中将轴值强制为科学计数法的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆