我繪制了下圖,它顯示了 x 軸上的數字。我想要的是在這些數字上添加逗號和加號。我期望的是“ 100,000”或“ 200,000”。盡管如此,我只能分別設法做到這一點,如:“100,000”或“ 100000”

我使用了以下代碼。
ggplot(data, aes(x = difference_gdp, y = difference_rate, color = region))
geom_point(size = 4)
xlab("Variation in GDP per capita, 1990 vs 2019")
ylab("Variation in age-standardised\nT2DM-attributable deaths per\n100,000 people, 1990 vs 2019")
stat_cor(method = "pearson", aes(x=difference_gdp, y = difference_rate, color = NA), digits = 2, p.accuracy = 0.05)
geom_smooth(method = 'lm', formula = 'y~x', se = FALSE, aes(color = NA))
scale_x_continuous(labels = function(x) sprintf("% d", x))
scale_y_continuous(labels = function(y) sprintf("% d", y))
我知道添加逗號的代碼是,scale_x_continuous(labels = comma)但我不知道將它添加到我以前的代碼中。
uj5u.com熱心網友回復:
我認為 scales 包涵蓋了這個用例
例如
scales::number_format(prefix = " ",big.mark = ",")(1000)
也許這有效,無法測驗
ggplot(data, aes(x = difference_gdp, y = difference_rate, color = region))
geom_point(size = 4) xlab("Variation in GDP per capita, 1990 vs 2019") ylab(
"Variation in age-standardised\nT2DM-attributable deaths per\n100,000 people, 1990 vs 2019"
) stat_cor(
method = "pearson",
aes(x = difference_gdp, y = difference_rate, color = NA),
digits = 2,
p.accuracy = 0.05
) geom_smooth(method = 'lm',
formula = 'y~x',
se = FALSE,
aes(color = NA)) scale_x_continuous(
labels = scales::number_format(prefix = " ",big.mark = ",")
) scale_y_continuous(
labels = scales::number_format(prefix = " ",big.mark = ",")
)
轉載請註明出處,本文鏈接:https://www.uj5u.com/caozuo/328493.html
