<div dir="ltr">Thanks to Benjamin Leutner and Brent Thorne for the invaluable help. All the techniques work very well. Thanks again. Looking forward to buying the next book</div><div class="gmail_extra"><br><div class="gmail_quote">On Wed, Jul 11, 2018 at 4:05 PM,  <span dir="ltr"><<a href="mailto:rs-ecology-request@lists.uni-wuerzburg.de" target="_blank">rs-ecology-request@lists.uni-wuerzburg.de</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">Send RS-ecology mailing list submissions to<br>
        <a href="mailto:rs-ecology@lists.uni-wuerzburg.de">rs-ecology@lists.uni-<wbr>wuerzburg.de</a><br>
<br>
To subscribe or unsubscribe via the World Wide Web, visit<br>
        <a href="https://lists.uni-wuerzburg.de/mailman/listinfo/rs-ecology" rel="noreferrer" target="_blank">https://lists.uni-wuerzburg.<wbr>de/mailman/listinfo/rs-ecology</a><br>
or, via email, send a message with subject or body 'help' to<br>
        <a href="mailto:rs-ecology-request@lists.uni-wuerzburg.de">rs-ecology-request@lists.uni-<wbr>wuerzburg.de</a><br>
<br>
You can reach the person managing the list at<br>
        <a href="mailto:rs-ecology-owner@lists.uni-wuerzburg.de">rs-ecology-owner@lists.uni-<wbr>wuerzburg.de</a><br>
<br>
When replying, please edit your Subject line so it is more specific<br>
than "Re: Contents of RS-ecology digest..."<br>
<br>
<br>
Today's Topics:<br>
<br>
   1. Re: ADDING SCALE BAR AND CUSTOM COLOURS IN ggplot2<br>
      (Benjamin Leutner)<br>
   2. Re: ADDING SCALE BAR AND CUSTOM COLOURS IN ggplot2 (Brent Thorne)<br>
<br>
<br>
------------------------------<wbr>------------------------------<wbr>----------<br>
<br>
Message: 1<br>
Date: Wed, 11 Jul 2018 13:12:47 +0200<br>
From: Benjamin Leutner <<a href="mailto:benjamin.leutner@uni-wuerzburg.de">benjamin.leutner@uni-<wbr>wuerzburg.de</a>><br>
To: <a href="mailto:rs-ecology@lists.uni-wuerzburg.de">rs-ecology@lists.uni-<wbr>wuerzburg.de</a><br>
Subject: Re: [RS-ecology] ADDING SCALE BAR AND CUSTOM COLOURS IN<br>
        ggplot2<br>
Message-ID: <<a href="mailto:ac4f2897-51e2-d9ac-b7df-5de47262281c@uni-wuerzburg.de">ac4f2897-51e2-d9ac-b7df-<wbr>5de47262281c@uni-wuerzburg.de</a>><br>
Content-Type: text/plain; charset="utf-8"; Format="flowed"<br>
<br>
You're close. You need to use scale_fill_manual()<br>
## Example (custom scale and NA handling):<br>
data(lsat)<br>
lsat[1:10,] <- NA ## add some NAs<br>
usc <- unsuperClass(lsat,nClasses=2)<br>
ggR(usc$map, geom_raster = TRUE, forceCat = TRUE) +<br>
 ??????? scale_fill_manual(values=c("<wbr>red", "green"),? na.translate = FALSE)<br>
<br>
<br>
## Scalebar:<br>
Here's what I use for local projected coordinate systems (e.g. UTM)<br>
Neither pretty, nor smart, but it does exactly that: a simple scalebar<br>
<br>
<a href="https://gist.github.com/bleutner/08fb0a5a893552b4413bbe02930f722d" rel="noreferrer" target="_blank">https://gist.github.com/<wbr>bleutner/<wbr>08fb0a5a893552b4413bbe02930f72<wbr>2d</a><br>
<br>
For more involved options have a look at the "ggsn" package (I'm not <br>
familiar with it, though)<br>
<br>
<br>
<br>
On 10.07.2018 19:54, Rop Willy wrote:<br>
><br>
> Hi,<br>
><br>
> The book is awesome and very helpful. I am doing practice and now in <br>
> Chapter 8. The code runs very well but I have three questions <br>
> concerning the final map produced:<br>
><br>
>  1. When I plot the classification map using ggplot2 I?d like to use<br>
>     my own color scheme but don?t know how. I?ve tried using<br>
>     *scale_colour_manual ()* from the ggplot2 package as well as<br>
>     *scalebar()* from ggsn package but haven?t really been successful.<br>
>     The code I used is as follows:<br>
><br>
> |// Used ggR() to plot the map map <- ggR(p224r63_2011_uc$map, <br>
> geom_raster = TRUE) // Then used custom theme elements to add other <br>
> features map + scale_x_continuous(expand = c(0, 0)) + <br>
> scale_y_continuous(expand = c(0, 0)) + labs(x = NULL, y = NULL) + <br>
> theme(axis.text.x = element_text(colour = "grey40", size = 6), <br>
> axis.text.y = element_text(colour = "grey40", size = 6, angle = 90, <br>
> hjust = 0.5), legend.text = element_text(colour = "grey10", size = 6), <br>
> legend.title = element_text(colour = "grey10", size = 8, face = <br>
> "bold"), axis.ticks = element_line(colour = "grey40")) |<br>
><br>
> How can I change the color scheme manually in ggplot2 instead of using <br>
> RColorBrewer and other palettes? NB: I?ve tried most options from <br>
> Stack Overflow and other references but nothing seems to work for me.<br>
><br>
> 1.<br>
><br>
>     How do I set a simple scale bar like the one used in the book<br>
>     and/or the variant of it in ggplot2?<br>
><br>
> 2.<br>
><br>
>     When I plot the map for the unsupervised classification (again in<br>
>     ggplot2) there?s a class called NA ( I suppose from unclassified<br>
>     pixels) that appear grey on the legend. Should it be there or<br>
>     should I remove it? If it is not necessary, how is it removed from<br>
>     the final map presentation?<br>
><br>
> Regards<br>
><br>
> ?<br>
><br>
><br>
> ______________________________<wbr>_________________<br>
> RS-ecology mailing list<br>
> <a href="mailto:RS-ecology@lists.uni-wuerzburg.de">RS-ecology@lists.uni-<wbr>wuerzburg.de</a><br>
> <a href="https://lists.uni-wuerzburg.de/mailman/listinfo/rs-ecology" rel="noreferrer" target="_blank">https://lists.uni-wuerzburg.<wbr>de/mailman/listinfo/rs-ecology</a><br>
<br>
-- <br>
Benjamin Leutner<br>
<br>
Department of Remote Sensing<br>
University of Wuerzburg<br>
Campus Hubland Nord 86<br>
97074 Wuerzburg, Germany<br>
<br>
Tel: +49-(0)931-31 89594<br>
Email: <a href="mailto:benjamin.leutner@uni-wuerzburg.de">benjamin.leutner@uni-<wbr>wuerzburg.de</a><br>
Web: <a href="http://www.fernerkundung.uni-wuerzburg.de" rel="noreferrer" target="_blank">http://www.fernerkundung.uni-<wbr>wuerzburg.de</a><br>
<br>
-------------- next part --------------<br>
An HTML attachment was scrubbed...<br>
URL: <<a href="http://lists.uni-wuerzburg.de/pipermail/rs-ecology/attachments/20180711/edaad4d1/attachment-0001.html" rel="noreferrer" target="_blank">http://lists.uni-wuerzburg.<wbr>de/pipermail/rs-ecology/<wbr>attachments/20180711/edaad4d1/<wbr>attachment-0001.html</a>><br>
<br>
------------------------------<br>
<br>
Message: 2<br>
Date: Wed, 11 Jul 2018 13:05:47 +0000<br>
From: Brent Thorne <<a href="mailto:bt10yi@brocku.ca">bt10yi@brocku.ca</a>><br>
To: Benjamin Leutner <<a href="mailto:benjamin.leutner@uni-wuerzburg.de">benjamin.leutner@uni-<wbr>wuerzburg.de</a>>,<br>
        "<a href="mailto:rs-ecology@lists.uni-wuerzburg.de">rs-ecology@lists.uni-<wbr>wuerzburg.de</a>"<br>
        <<a href="mailto:rs-ecology@lists.uni-wuerzburg.de">rs-ecology@lists.uni-<wbr>wuerzburg.de</a>><br>
Subject: Re: [RS-ecology] ADDING SCALE BAR AND CUSTOM COLOURS IN<br>
        ggplot2<br>
Message-ID:<br>
        <<a href="mailto:YTOPR0101MB1273014AF9510D62870267B8D35A0@YTOPR0101MB1273.CANPRD01.PROD.OUTLOOK.COM">YTOPR0101MB1273014AF9510D6287<wbr>0267B8D35A0@YTOPR0101MB1273.<wbr>CANPRD01.PROD.OUTLOOK.COM</a>><br>
<br>
Content-Type: text/plain; charset="utf-8"<br>
<br>
For the scale bar I would recommended the `ggspatial` package available on CRAN<<a href="https://cran.r-project.org/web/packages/ggspatial/index.html" rel="noreferrer" target="_blank">https://cran.r-project.<wbr>org/web/packages/ggspatial/<wbr>index.html</a>> or on github<<a href="https://github.com/paleolimbot/ggspatial" rel="noreferrer" target="_blank">https://github.com/<wbr>paleolimbot/ggspatial</a>>. It has automatically applied spatially aware scalebars with only a simple `annotation_scalebar()+` needed.  There are also other nice cartographic options available in this package like vectorized north arrows, where `ggsn` uses a png file for its north arrow options which is not ideal for scaling. Here is the ReadMe<<a href="https://github.com/paleolimbot/ggspatial/blob/master/README.md" rel="noreferrer" target="_blank">https://github.com/<wbr>paleolimbot/ggspatial/blob/<wbr>master/README.md</a>> documentation from GitHub.<br>
<br>
W. Brent Thorne, BSc<br>
Master of Science Candidate<br>
Brock University | Department of Earth Sciences<br>
Niagara Region | 1812 Sir Isaac Brock Way | St. Catharines, Ontario, L2S 3A1<br>
<br>
______________________________<wbr>__<br>
From: RS-ecology <<a href="mailto:rs-ecology-bounces@lists.uni-wuerzburg.de">rs-ecology-bounces@lists.uni-<wbr>wuerzburg.de</a>> on behalf of Benjamin Leutner <<a href="mailto:benjamin.leutner@uni-wuerzburg.de">benjamin.leutner@uni-<wbr>wuerzburg.de</a>><br>
Sent: Wednesday, July 11, 2018 7:12:47 AM<br>
To: <a href="mailto:rs-ecology@lists.uni-wuerzburg.de">rs-ecology@lists.uni-<wbr>wuerzburg.de</a><br>
Subject: Re: [RS-ecology] ADDING SCALE BAR AND CUSTOM COLOURS IN ggplot2<br>
<br>
You're close. You need to use scale_fill_manual()<br>
## Example (custom scale and NA handling):<br>
data(lsat)<br>
lsat[1:10,] <- NA ## add some NAs<br>
usc <- unsuperClass(lsat,nClasses=2)<br>
ggR(usc$map, geom_raster = TRUE, forceCat = TRUE) +<br>
        scale_fill_manual(values=c("<wbr>red", "green"),  na.translate = FALSE)<br>
<br>
<br>
## Scalebar:<br>
Here's what I use for local projected coordinate systems (e.g. UTM)<br>
Neither pretty, nor smart, but it does exactly that: a simple scalebar<br>
<br>
<a href="https://gist.github.com/bleutner/08fb0a5a893552b4413bbe02930f722d" rel="noreferrer" target="_blank">https://gist.github.com/<wbr>bleutner/<wbr>08fb0a5a893552b4413bbe02930f72<wbr>2d</a><br>
<br>
For more involved options have a look at the "ggsn" package (I'm not familiar with it, though)<br>
<br>
<br>
<br>
On 10.07.2018 19:54, Rop Willy wrote:<br>
<br>
Hi,<br>
<br>
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:<br>
<br>
  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:<br>
<br>
<br>
// Used ggR() to plot the map<br>
<br>
map <- ggR(p224r63_2011_uc$map, geom_raster = TRUE)<br>
<br>
// Then used custom theme elements to add other features<br>
<br>
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"))<br>
<br>
<br>
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.<br>
<br>
  1.  How do I set a simple scale bar like the one used in the book and/or the variant of it in ggplot2?<br>
<br>
  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?<br>
<br>
Regards<br>
<br>
?<br>
<br>
<br>
<br>
______________________________<wbr>_________________<br>
RS-ecology mailing list<br>
<a href="mailto:RS-ecology@lists.uni-wuerzburg.de">RS-ecology@lists.uni-<wbr>wuerzburg.de</a><mailto:<a href="mailto:RS-ecology@lists.uni-wuerzburg.de">RS-<wbr>ecology@lists.uni-wuerzburg.de</a><wbr>><br>
<a href="https://lists.uni-wuerzburg.de/mailman/listinfo/rs-ecology" rel="noreferrer" target="_blank">https://lists.uni-wuerzburg.<wbr>de/mailman/listinfo/rs-ecology</a><br>
<br>
<br>
<br>
--<br>
Benjamin Leutner<br>
<br>
Department of Remote Sensing<br>
University of Wuerzburg<br>
Campus Hubland Nord 86<br>
97074 Wuerzburg, Germany<br>
<br>
Tel: +49-(0)931-31 89594<br>
Email: <a href="mailto:benjamin.leutner@uni-wuerzburg.de">benjamin.leutner@uni-<wbr>wuerzburg.de</a><mailto:<a href="mailto:benjamin.leutner@uni-wuerzburg.de">benjamin.<wbr>leutner@uni-wuerzburg.de</a>><br>
Web: <a href="http://www.fernerkundung.uni-wuerzburg.de" rel="noreferrer" target="_blank">http://www.fernerkundung.uni-<wbr>wuerzburg.de</a><br>
<br>
-------------- next part --------------<br>
An HTML attachment was scrubbed...<br>
URL: <<a href="http://lists.uni-wuerzburg.de/pipermail/rs-ecology/attachments/20180711/b8f60a80/attachment.html" rel="noreferrer" target="_blank">http://lists.uni-wuerzburg.<wbr>de/pipermail/rs-ecology/<wbr>attachments/20180711/b8f60a80/<wbr>attachment.html</a>><br>
<br>
------------------------------<br>
<br>
Subject: Digest Footer<br>
<br>
______________________________<wbr>_________________<br>
RS-ecology mailing list<br>
<a href="mailto:RS-ecology@lists.uni-wuerzburg.de">RS-ecology@lists.uni-<wbr>wuerzburg.de</a><br>
<a href="https://lists.uni-wuerzburg.de/mailman/listinfo/rs-ecology" rel="noreferrer" target="_blank">https://lists.uni-wuerzburg.<wbr>de/mailman/listinfo/rs-ecology</a><br>
<br>
<br>
------------------------------<br>
<br>
End of RS-ecology Digest, Vol 29, Issue 2<br>
******************************<wbr>***********<br>
</blockquote></div><br></div>