我已经绘制了下图,它显示了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),但我不知道如何将它添加到前面的代码中。
发布于 2021-10-15 17:00:31
我认为scales包涵盖了这个用例
e.g
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://stackoverflow.com/questions/69588182
复制相似问题