removing scientific notation from a ggplot map legend

前端 未结 1 1230
轮回少年
轮回少年 2020-12-20 00:34

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

相关标签:
1条回答
  • 2020-12-20 01:15

    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
    

    0 讨论(0)
提交回复
热议问题