Aru*_*run 110
我想你正在寻找这个:
require(ggplot2)
df <- data.frame(x=seq(1, 1e9, length.out=100), y=sample(100))
# displays x-axis in scientific notation
p <- ggplot(data = df, aes(x=x, y=y)) + geom_line() + geom_point()
p
# displays as you require
require(scales)
p + scale_x_continuous(labels = comma)
Run Code Online (Sandbox Code Playgroud)
jub*_*uba 54
你尝试过这样的事情:
options(scipen=10000)
Run Code Online (Sandbox Code Playgroud)
在策划之前?
Der*_*ran 28
只是对@Arun所做的更新,因为我今天尝试了它并且它没有用,因为它实现了
+ scale_x_continuous(labels = scales::comma)
Run Code Online (Sandbox Code Playgroud)
use*_*472 11
作为更通用的解决方案,您可以使用scales::format_format删除科学记数法.这也使您可以很好地控制标签显示的准确程度,scales::comma而不仅仅是数量级的逗号分隔.
例如:
require(ggplot2)
require(scales)
df <- data.frame(x=seq(1, 1e9, length.out=100), y=sample(100))
# Here we define spaces as the big separator
point <- format_format(big.mark = " ", decimal.mark = ",", scientific = FALSE)
# Plot it
p <- ggplot(data = df, aes(x=x, y=y)) + geom_line() + geom_point()
p + scale_x_continuous(labels = point)
Run Code Online (Sandbox Code Playgroud)
Wil*_*zyk 10
有一个不需要比例库的解决方案。
你可以试试:
# To deactivate scientific notation on y-axis:
p + scale_y_continuous(labels = function(x) format(x, scientific = FALSE))
# To activate scientific notation on y-axis:
p + scale_y_continuous(labels = function(x) format(x, scientific = TRUE))
# To deactivate scientific notation on x-axis:
p + scale_x_continuous(labels = function(x) format(x, scientific = FALSE))
# To activate scientific notation on x-axis:
p + scale_x_continuous(labels = function(x) format(x, scientific = TRUE))
Run Code Online (Sandbox Code Playgroud)
小智 5
将原始问题扩展为也包含分数,即 1、0.1、0.01、0.001 等,并避免尾随零
p + scale_x_continuous(labels = function(x) sprintf("%g", x))
Run Code Online (Sandbox Code Playgroud)
如果您还想使用逗号作为千位分隔符,可以使用以下命令:
p + scale_x_continuous(labels=function(x) format(x, big.mark = ",", scientific = FALSE))
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
63135 次 |
| 最近记录: |