【问题标题】:removing scientific notation from a ggplot map legend从 ggplot 地图图例中删除科学记数法
【发布时间】:2015-08-28 13:42:40
【问题描述】:

我正在用 ggplot 制作一个等值线,我正在尝试将我的图例的标签放在框架中,但 R 一直将标记的值以科​​学记数法表示。有谁知道解决这个问题的方法?当我的标签值较小时,我有以下代码可以正常工作,但我需要包含范围。

 ta<- quantile(look13$capcpi,c(0, 0.2, 0.4, 0.6, 0.8, 1.0) )
 t<- c('$35,141-$37,916', '$37,916-$40,236','$40,236-$43,364','$43,364-$45,280', '$45,280-$59,688')
 look13$capcpi_q<- cut(look13$capcpi,ta, lables= t, include.lowest = TRUE)
 lookmap<- merge(st,look13, by.x='id', by.y= 'area')
 realpi<- ggplot(lookmap, aes(x=long, y=lat, group=group, fill= capcpi_q))+
          geom_path() + geom_polygon(color='black')+ 
          scale_fill_manual(values= pal)+ theme_clean()

【问题讨论】:

  • 您的代码不可重现。我们没有数据。

标签: r ggplot2


【解决方案1】:

一般情况下,您可以使用scales 包和label 参数到scale_color_continuous(或discrete):

library(ggplot2)
library(scales)
library(ggthemes)

# make up some data

dat <- data.frame(state=tolower(rownames(USArrests)), 
                  rate=USArrests$Murder*10000000,
                  stringsAsFactors=FALSE)

us <- map_data("state")

gg <- ggplot()
gg <- gg + geom_map(data=us, map=us, 
                    aes(x=long, y=lat, map_id=region),
                    color="#7f7f7f", size=0.15, fill="white")
gg <- gg + geom_map(data=dat, map=us,
                    aes(fill=rate, map_id=state))
gg <- gg + scale_fill_continuous(label=comma)
gg <- gg + coord_map("albers", 39, 42)
gg <- gg + theme_map()
gg

【讨论】:

  • 经过一番研究,现在应该是labels = label_comma()
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 2020-08-04
  • 2020-12-30
  • 1970-01-01
  • 2017-08-31
  • 1970-01-01
  • 2023-03-28
  • 1970-01-01
相关资源
最近更新 更多