gpt4 book ai didi

r - 如何更改ggplot2中图例标签上的科学记数法

转载 作者:行者123 更新时间:2023-12-02 20:16:56 25 4
gpt4 key购买 nike

我编写此代码是为了创建 map 。

ggplot(data = Canada2015_Import_3) +
borders(database = "world",
colour = "grey60",
fill="grey90") +
geom_polygon(aes(x=long, y=lat, group = group, fill = Trade_Value_mean),
color = "grey60") +
scale_fill_gradient(low = "blue", high = "red", name = "Trade Value") +
ggtitle("Canadien Imports in 2015") +
xlab("") + ylab("") +
theme(panel.background = element_blank(),
plot.title = element_text(face = "bold"),
axis.title.x=element_blank(),
axis.text.x=element_blank(),
axis.ticks.x=element_blank(),
axis.title.y=element_blank(),
axis.text.y=element_blank(),
axis.ticks.y=element_blank())

这张 map 给了我一个带有科学计数法的图例,我想将其更改为普通或逗号。

enter image description here

有人知道怎么做吗?

这是我的数据框的基本结构。

Country   Trade_Value_mean  long      lat     group order subregion
Afghanistan 2359461 74.89131 37.23164 2 12 <NA>

感谢所有帮助。

最佳答案

我明白了。基本上,您所要做的就是插入比例库并添加标签=逗号。这是修改后的代码:

library(scales) 

ggplot(data = Canada2015_Import_3) +
borders(database = "world",
colour = "grey60",
fill="grey90") +
geom_polygon(aes(x=long, y=lat, group = group, fill = Trade_Value_mean),
color = "grey60") +
scale_fill_gradient(low = "blue", high = "red", name = "Trade Value", labels = comma) +
ggtitle("Canadien Imports in 2015") +
xlab("") + ylab("") +
theme(panel.background = element_blank(),
plot.title = element_text(face = "bold"),
axis.title.x=element_blank(),
axis.text.x=element_blank(),
axis.ticks.x=element_blank(),
axis.title.y=element_blank(),
axis.text.y=element_blank(),
axis.ticks.y=element_blank())

关于r - 如何更改ggplot2中图例标签上的科学记数法,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/40072971/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com