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
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