[RS-ecology] ADDING SCALE BAR AND CUSTOM COLOURS IN ggplot2

Benjamin Leutner benjamin.leutner at uni-wuerzburg.de
Wed Jul 11 13:12:47 CEST 2018


You're close. You need to use scale_fill_manual()
## Example (custom scale and NA handling):
data(lsat)
lsat[1:10,] <- NA ## add some NAs
usc <- unsuperClass(lsat,nClasses=2)
ggR(usc$map, geom_raster = TRUE, forceCat = TRUE) +
         scale_fill_manual(values=c("red", "green"),  na.translate = FALSE)


## Scalebar:
Here's what I use for local projected coordinate systems (e.g. UTM)
Neither pretty, nor smart, but it does exactly that: a simple scalebar

https://gist.github.com/bleutner/08fb0a5a893552b4413bbe02930f722d

For more involved options have a look at the "ggsn" package (I'm not 
familiar with it, though)



On 10.07.2018 19:54, Rop Willy wrote:
>
> Hi,
>
> The book is awesome and very helpful. I am doing practice and now in 
> Chapter 8. The code runs very well but I have three questions 
> concerning the final map produced:
>
>  1. When I plot the classification map using ggplot2 I’d like to use
>     my own color scheme but don’t know how. I’ve tried using
>     *scale_colour_manual ()* from the ggplot2 package as well as
>     *scalebar()* from ggsn package but haven’t really been successful.
>     The code I used is as follows:
>
> |// Used ggR() to plot the map map <- ggR(p224r63_2011_uc$map, 
> geom_raster = TRUE) // Then used custom theme elements to add other 
> features map + scale_x_continuous(expand = c(0, 0)) + 
> scale_y_continuous(expand = c(0, 0)) + labs(x = NULL, y = NULL) + 
> theme(axis.text.x = element_text(colour = "grey40", size = 6), 
> axis.text.y = element_text(colour = "grey40", size = 6, angle = 90, 
> hjust = 0.5), legend.text = element_text(colour = "grey10", size = 6), 
> legend.title = element_text(colour = "grey10", size = 8, face = 
> "bold"), axis.ticks = element_line(colour = "grey40")) |
>
> How can I change the color scheme manually in ggplot2 instead of using 
> RColorBrewer and other palettes? NB: I’ve tried most options from 
> Stack Overflow and other references but nothing seems to work for me.
>
> 1.
>
>     How do I set a simple scale bar like the one used in the book
>     and/or the variant of it in ggplot2?
>
> 2.
>
>     When I plot the map for the unsupervised classification (again in
>     ggplot2) there’s a class called NA ( I suppose from unclassified
>     pixels) that appear grey on the legend. Should it be there or
>     should I remove it? If it is not necessary, how is it removed from
>     the final map presentation?
>
> Regards
>
>>
>
> _______________________________________________
> RS-ecology mailing list
> RS-ecology at lists.uni-wuerzburg.de
> https://lists.uni-wuerzburg.de/mailman/listinfo/rs-ecology

-- 
Benjamin Leutner

Department of Remote Sensing
University of Wuerzburg
Campus Hubland Nord 86
97074 Wuerzburg, Germany

Tel: +49-(0)931-31 89594
Email: benjamin.leutner at uni-wuerzburg.de
Web: http://www.fernerkundung.uni-wuerzburg.de

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.uni-wuerzburg.de/pipermail/rs-ecology/attachments/20180711/edaad4d1/attachment.html>


More information about the RS-ecology mailing list