How to change scientific notation on legend labels in ggplot2

前端 未结 2 732
离开以前
离开以前 2020-12-31 12:22

I wrote this code to create a map.

ggplot(data = Canada2015_Import_3) +
  borders(database = \"world\", 
          colour = \"grey60\",
          fill=\"gre         


        
相关标签:
2条回答
  • 2020-12-31 12:57

    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())
    
    0 讨论(0)
  • 2020-12-31 13:01

    you can also use at the beginning of your code:

    options(scipen=10000)
    
    0 讨论(0)
提交回复
热议问题