簡體   English   中英

更改 ggplot 中的千位分隔符

[英]Change the thousands separator in a ggplot

在使用 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

像這樣它給出了一個逗號:

p + scale_y_continuous(labels=comma)

你如何得到一個點作為千位分隔符? 除了http://docs.ggplot2.org/0.9.3.1/scale_continuous.html上的一些示例之外,我找不到關於存在哪些類型的其他標簽的文檔。

提前致謝,

極限競速

p + scale_y_continuous(labels=function(x) format(x, big.mark = ".", scientific = FALSE))

很好的答案。 在定義千位分隔符時,最好將小數分隔符也定義為逗號,以避免錯誤。

p + scale_y_continuous(labels=function(x) format(x, big.mark = ".", decimal.mark = ",", scientific = FALSE))

這也有效:

p + scale_y_continuous(labels = scales::comma)

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM