如何在ggplot2中更改图例标签上的科学计数法 [英] How to change scientific notation on legend labels in ggplot2
本文介绍了如何在ggplot2中更改图例标签上的科学计数法的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我写了这段代码来创建地图.
I wrote this code to create a 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())
这张地图给了我一个具有科学符号的传说,我想将其更改为普通或逗号.
This map gives me a legend with scientific notation, and I would like to change it to normal or with commas.
有人知道该怎么做吗?
Does anybody know how to do that?
这是我的数据框的基本结构.
Here is the basic structure of my data frame.
Country Trade_Value_mean long lat group order subregion
Afghanistan 2359461 74.89131 37.23164 2 12 <NA>
感谢所有帮助.
推荐答案
我知道了.基本上,您要做的就是插入秤库并添加标签=逗号.这是修改后的代码:
I figured it out. Basically all you have to do is insert the scales library and add labels = comma. Here's the modified code :
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())
这篇关于如何在ggplot2中更改图例标签上的科学计数法的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文