I want to round off values showing in legend items like from 18128740 to just 18 million
here is my code:
p<-print(ggplot(data = Map_plot, aes(x = long, y = lat, group = group)) +
ggtitle(vars$names[k]) +
geom_polygon(aes(fill=Map_plot[,vars$variables[k]]), color = 'black', size = 0.5) +
scale_fill_distiller(palette = "Spectral",
limits = c(min(Map_plot[,vars$variables[k]]),
max(Map_plot[,vars$variables[k]])),
breaks = seq(min(Map_plot[,vars$variables[k]]),
max(Map_plot[,vars$variables[k]]),
mean(Map_plot[,vars$variables[k]])/2)) +
coord_fixed(1) +
theme(
legend.key = element_rect(fill = NA, colour = "black"),
legend.key.width = unit(0.4, "cm"),
legend.key.height = unit(1.5, "cm"),
legend.spacing.x = unit(0.5, 'cm'),
legend.spacing.y = unit(2.0, 'cm'),
legend.text = element_text(size = 9)) +
guides(fill=guide_colorbar(title='Legend', barwidth = 1, title.vjust = -15)))
ggsave(p, file=paste0("plot_state_", vars$variables[k],".jpg"), width = 14, height = 10, units = "cm")