Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
801 views
in Technique[技术] by (71.8m points)

r - removing scientific notation from a ggplot map legend

I am making a choropleth with ggplot and I am trying to fit the labels for my legend in the frame but R keeps putting the labeled values in scientific notation. Does anyone know of a way to address this? I have the following code which works fine when the values of my labels are smaller, but I need to include the range.

 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()
See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

Generally, you can use the scales package and a label parameter to scale_color_continuous (or 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


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...