更改ggplot中的千位分隔符

For*_*zaa 13 r decimal scale separator ggplot2

在使用ggplot创建条形图时,我遇到麻烦,获得首选的千位分隔符.我希望数千个用点而不是逗号分隔.像这样它没有分隔符:

require(ggplot2)
require(scales) 
options(scipen=10)
D = data.frame(x=c(1,2),y=c(1000001,500000))
p = ggplot(D,aes(x,y)) + geom_bar(stat="identity") 
p
Run Code Online (Sandbox Code Playgroud)

并且像这样它给出一个逗号:

p + scale_y_continuous(labels=comma)
Run Code Online (Sandbox Code Playgroud)

你怎么得到一个点数千分隔符?除了http://docs.ggplot2.org/0.9.3.1/scale_continuous.html上的一些示例之外,我找不到关于哪些类型的其他标签存在的文档.

提前致谢,

极限竞速

luk*_*keA 23

p + scale_y_continuous(labels=function(x) format(x, big.mark = ".", scientific = FALSE))
Run Code Online (Sandbox Code Playgroud)

  • 我想补充一点,通常需要将修剪选项(请参见http://stackoverflow.com/questions/14665461/european-french-thousand-separator-in-ggplot)添加到x上的函数中轴,因为格式可能会将轴值向右移动.因此它们不再对齐. (2认同)

BML*_*pes 7

很好的答案。在定义千位分隔符时,最好将小数分隔符也定义为逗号,以避免错误。

p + scale_y_continuous(labels=function(x) format(x, big.mark = ".", decimal.mark = ",", scientific = FALSE))
Run Code Online (Sandbox Code Playgroud)


Gui*_*nca 5

这也有效:

p + scale_y_continuous(labels = scales::comma)
Run Code Online (Sandbox Code Playgroud)