Closed josephholler closed 2 months ago
Anyone else's map have the legend in the wrong order (-1, -2, 0, 1, 2)? Tried messing with "levels =" and "ordered()" but couldn't figure it out. edit: fixed it by just using Paint to switch the order in the png
I was having the same order issue, and in case anyone else is running into it, one workaround is to use scale_fill_manual()
and set both limits
(which takes care of the order) and values
(which picks the colors). For instance:
map3 =ggplot() +
geom_sf(data = ea,
aes(fill = EA),
color = NA) +
geom_sf(
data = fig4compare,
aes(fill = factor(difference)),
color = "white",
lwd = .2
) +
scale_fill_manual(limits = c("-2","-1","0","1","2","Missing Data","Major Lakes of Malawi","National Parks and Reserves"),
values = c("-2"="#e66101","-1"="#fdb863","0"="#cccccc","1"="#b2abd2","2"="#5e3c99","Missing Data"="#000000","Major Lakes of Malawi"="lightblue","National Parks and Reserves"="#D9EABB"))+
scale_x_continuous(breaks = c(33,34,35,36)) +
labs(title = "Title") +
theme_minimal() +
theme(legend.title = element_blank())
map3
Thanks Vincent!
From: vinfalardeau @.> Sent: Monday, April 26, 2021 3:20:55 PM To: GIS4DEV/GIS4DEV.github.io @.> Cc: Tango, Maddie @.>; Comment @.> Subject: Re: [GIS4DEV/GIS4DEV.github.io] Tips for mapping fig4 comparison (#41)
I was having the same order issue, and in case anyone else is running into it, one workaround is to use scale_fill_manual() and set both limits (which takes care of the order) and values (which picks the colors). For instance:
map3 =ggplot() + geom_sf(data = ea, aes(fill = EA), color = NA) + geom_sf( data = fig4compare, aes(fill = factor(difference)), color = "white", lwd = .2 ) + scale_fill_manual(limits = c("-2","-1","0","1","2","Missing Data","Major Lakes of Malawi","National Parks and Reserves"), values = c("-2"="#e66101","-1"="#fdb863","0"="#cccccc","1"="#b2abd2","2"="#5e3c99","Missing Data"="#0","Major Lakes of Malawi"="lightblue","National Parks and Reserves"="#D9EABB"))+ scale_x_continuous(breaks = c(33,34,35,36)) + labs(title = "Title") + theme_minimal() + theme(legend.title = element_blank()) map3
— You are receiving this because you commented. Reply to this email directly, view it on GitHubhttps://github.com/GIS4DEV/GIS4DEV.github.io/issues/41#issuecomment-827084117, or unsubscribehttps://github.com/notifications/unsubscribe-auth/AOZTNMNYO67JXXI24O2OOZLTKW4JPANCNFSM43TJWLBQ.
The data source for
aes()
can be wrapped in afactor
function as such:aes( fill = factor( difference ))
so that you can set up a manual classification.Then use a
scale_fill_manual()
to set a unique color for each of your unique results.If you want to select great colors for this classification, you can pick the HTML color hex codes from colorbrewer: https://colorbrewer2.org/