我注意到,使用scales
包,可以使用內部的scales = dollar
選項在軸上顯示美元,例如scale_y_log10()
。像scales = euro
這樣的選項似乎缺乏。有沒有一種簡單的方法可以達到同樣的效果?ggplot中的歐元符號:秤包
5
A
回答
12
很容易修改dollar_format並將符號更改爲歐元。運行這個並把它放在這樣的代碼,你會打電話dollar_format
euro_format <- function(largest_with_cents = 100000) {
function(x) {
x <- round_any(x, 0.01)
if (max(x, na.rm = TRUE) < largest_with_cents &
!all(x == floor(x), na.rm = TRUE)) {
nsmall <- 2L
} else {
x <- round_any(x, 1)
nsmall <- 0L
}
str_c("€", format(x, nsmall = nsmall, trim = TRUE, big.mark = ",", scientific = FALSE, digits=1L))
}
}
6
您可以使用dollar_format
的prefix
和suffix
參數例如像這樣:
library(ggplot2)
library(scales)
ggplot(diamonds) + geom_point(aes(x = carat, y = price)) + scale_y_continuous(labels = dollar_format(suffix = "€", prefix = ""))
相關問題
- 1. 歐元符號
- 2. 茉莉SMPP歐元符號
- 3. 回聲歐元符號
- 4. imagettftext和歐元符號
- 5. 歐元符號轉換爲問號
- 6. 正則表達式的歐元符號(€)
- 7. 歐元符號越獄輸出:?€
- 8. MySQL ::連接器/淨歐元符號
- 9. 用pgf/tikz創建歐元符號
- 10. 歐元符號JNA皈依問題
- 11. 在閃亮的R應用程序中顯示歐元符號
- 12. EuroCRM賬戶中的歐元/貨幣符號
- 13. 我如何使用逗號和歐元符號
- 14. ggplot facet strip text中的符號
- 15. 歐元符號不能正確顯示在HTML中
- 16. 如何把歐元符號放在html R plotly圖中?
- 17. FlyingSaucer(xhtmlrenderer):在PDF中呈現€(歐元)符號
- 18. 無法在「C」程序中打印歐元符號
- 19. 如何將歐元符號存儲在mysql數據庫中?
- 20. 如何在C中生成歐元符號?
- 21. 編碼 - 顯示歐元符號和更多 - UTF-8字符集
- 22. 檢查字符串是否以歐元/英鎊符號開頭
- 23. oracle歐元字符問題
- 24. 特殊字符歐元
- 25. Oracle JDBC歐元字符
- 26. 在表單中提交歐元符號並獲取額外的2個字符
- 27. 奇怪的現象:Java轉義歐元符號
- 28. 嵌入支持歐元符號的字體
- 29. 不能歐元貨幣轉換成它的符號
- 30. php json_encode適用於Android的歐元符號
非常感謝,這工作正常!對於那些仍然感到困惑的人來說,除了'ggplot'和'scales'之外,您還需要加載'reshape'和'stringr'包來完成這個工作。 – 2012-08-14 06:29:25
在有限的測試中,我發現以下工作,它只依賴於''ggplot2''和'''':''euroFrance < - function(x)paste0(format(x,big.mark =「 「,decimal.mark =」,「,trim = TRUE, scientific = FALSE),」€「)}''(我選擇了法國風格與Luciano的例子進行對比,並展示了可能性的範圍)。或者換句話說,如果你不需要擔心舍入或修整小數點,一個簡單的函數就可以做到。哦,你會這樣稱呼它:''+ scale_y_continuous(labels = euroFrance,breaks = etc.'' – PatrickT 2014-12-20 18:08:27