繁体   English   中英

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

[英]How to change scientific notation on legend labels in ggplot2

我写了这段代码来创建一个地图。

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())

这张地图给了我一个带有科学记数法的图例,我想把它改成正常或用逗号。

在此输入图像描述

有谁知道怎么做?

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

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

所有帮助表示赞赏。

我想到了。 基本上你要做的就是插入比例库并添加labels =逗号。 这是修改后的代码:

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())

您也可以在代码的开头使用:

options(scipen=10000)

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM