2015-08-28 105 views
2

我正在用ggplot製作一個choropleth,我試圖將我的圖例的標籤放在框架中,但是R始終將標註的值放在科學記數法中。有誰知道解決這個問題的方法嗎?我有下面的代碼,當我的標籤值較小時工作正常,但我需要包含範圍。從ggplot地圖圖例中刪除科學記數法

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

你的代碼是不可重複的。我們沒有這些數據。 – hrbrmstr

回答

3

一般情況下,你可以使用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 

enter image description here

+0

這非常有幫助謝謝 – bryven