Change range of values of the legend

Previous Topic Next Topic
 
classic Classic list List threaded Threaded
9 messages Options
Reply | Threaded
Open this post in threaded view
|

Change range of values of the legend

Stefano Sofia
Dear list users,
suppose that I have this simple raster:

library(raster)
xy <- matrix(rnorm(400),20,20)
rast <- raster(xy)

plot(rast) gives me a legend with range (-3,3).
I would like to change the range of the legend to (-5,5), for example. I tried with

plot(rast, legend=FALSE, axes=FALSE)
r.range <- c(-5, 5)
plot(rast, legend.only=TRUE, axis.args=list(at=seq(r.range[1], r.range[2], 1), labels=seq(r.range[1], r.range[2], 1)))

but this does not expand the values of the legend.
Could somebody give me some hints?

Thank you
Stefano


         (oo)
--oOO--( )--OOo----------------
Stefano Sofia PhD
Area Meteorologica e  Area nivologica - Centro Funzionale
Servizio Protezione Civile - Regione Marche
Via del Colle Ameno 5
60126 Torrette di Ancona, Ancona
Uff: 071 806 7743
E-mail: [hidden email]
---Oo---------oO----------------

________________________________

AVVISO IMPORTANTE: Questo messaggio di posta elettronica può contenere informazioni confidenziali, pertanto è destinato solo a persone autorizzate alla ricezione. I messaggi di posta elettronica per i client di Regione Marche possono contenere informazioni confidenziali e con privilegi legali. Se non si è il destinatario specificato, non leggere, copiare, inoltrare o archiviare questo messaggio. Se si è ricevuto questo messaggio per errore, inoltrarlo al mittente ed eliminarlo completamente dal sistema del proprio computer. Ai sensi dell’art. 6 della DGR n. 1394/2008 si segnala che, in caso di necessità ed urgenza, la risposta al presente messaggio di posta elettronica può essere visionata da persone estranee al destinatario.
IMPORTANT NOTICE: This e-mail message is intended to be received only by persons entitled to receive the confidential information it may contain. E-mail messages to clients of Regione Marche may contain information that is confidential and legally privileged. Please do not read, copy, forward, or store this message unless you are an intended recipient of it. If you have received this message in error, please forward it to the sender and delete it completely from your computer system.

--
This message was scanned by Libra ESVA and is believed to be clean.


        [[alternative HTML version deleted]]

_______________________________________________
R-sig-Geo mailing list
[hidden email]
https://stat.ethz.ch/mailman/listinfo/r-sig-geo
Reply | Threaded
Open this post in threaded view
|

Re: Change range of values of the legend

Ben Tupper
Hi,

Try

plot(rast, zlim = c(-5, 5))

I think the zlim argument is passed through to graphics::image() via fields::image.plot() which raster::plot() calls.  I know it isn't super obvious until until you re-read the docs about 2000 times.

Cheers,
Ben


> On Feb 9, 2018, at 9:39 AM, Stefano Sofia <[hidden email]> wrote:
>
> Dear list users,
> suppose that I have this simple raster:
>
> library(raster)
> xy <- matrix(rnorm(400),20,20)
> rast <- raster(xy)
>
> plot(rast) gives me a legend with range (-3,3).
> I would like to change the range of the legend to (-5,5), for example. I tried with
>
> plot(rast, legend=FALSE, axes=FALSE)
> r.range <- c(-5, 5)
> plot(rast, legend.only=TRUE, axis.args=list(at=seq(r.range[1], r.range[2], 1), labels=seq(r.range[1], r.range[2], 1)))
>
> but this does not expand the values of the legend.
> Could somebody give me some hints?
>
> Thank you
> Stefano
>
>
>         (oo)
> --oOO--( )--OOo----------------
> Stefano Sofia PhD
> Area Meteorologica e  Area nivologica - Centro Funzionale
> Servizio Protezione Civile - Regione Marche
> Via del Colle Ameno 5
> 60126 Torrette di Ancona, Ancona
> Uff: 071 806 7743
> E-mail: [hidden email]
> ---Oo---------oO----------------
>
> ________________________________
>
> AVVISO IMPORTANTE: Questo messaggio di posta elettronica può contenere informazioni confidenziali, pertanto è destinato solo a persone autorizzate alla ricezione. I messaggi di posta elettronica per i client di Regione Marche possono contenere informazioni confidenziali e con privilegi legali. Se non si è il destinatario specificato, non leggere, copiare, inoltrare o archiviare questo messaggio. Se si è ricevuto questo messaggio per errore, inoltrarlo al mittente ed eliminarlo completamente dal sistema del proprio computer. Ai sensi dell’art. 6 della DGR n. 1394/2008 si segnala che, in caso di necessità ed urgenza, la risposta al presente messaggio di posta elettronica può essere visionata da persone estranee al destinatario.
> IMPORTANT NOTICE: This e-mail message is intended to be received only by persons entitled to receive the confidential information it may contain. E-mail messages to clients of Regione Marche may contain information that is confidential and legally privileged. Please do not read, copy, forward, or store this message unless you are an intended recipient of it. If you have received this message in error, please forward it to the sender and delete it completely from your computer system.
>
> --
> This message was scanned by Libra ESVA and is believed to be clean.
>
>
> [[alternative HTML version deleted]]
>
> _______________________________________________
> R-sig-Geo mailing list
> [hidden email]
> https://stat.ethz.ch/mailman/listinfo/r-sig-geo

Ben Tupper
Bigelow Laboratory for Ocean Sciences
60 Bigelow Drive, P.O. Box 380
East Boothbay, Maine 04544
http://www.bigelow.org

Ecocast Reports: http://seascapemodeling.org/ecocast.html
Tick Reports: https://report.bigelow.org/tick/
Jellyfish Reports: https://jellyfish.bigelow.org/jellyfish/




        [[alternative HTML version deleted]]

_______________________________________________
R-sig-Geo mailing list
[hidden email]
https://stat.ethz.ch/mailman/listinfo/r-sig-geo
Reply | Threaded
Open this post in threaded view
|

Re: Change range of values of the legend

Stefano Sofia
Thank you. You are right!

         (oo)
--oOO--( )--OOo----------------
Stefano Sofia PhD
Area Meteorologica e  Area nivologica - Centro Funzionale
Servizio Protezione Civile - Regione Marche
Via del Colle Ameno 5
60126 Torrette di Ancona, Ancona
Uff: 071 806 7743
E-mail: [hidden email]
---Oo---------oO----------------
________________________________
Da: Ben Tupper [[hidden email]]
Inviato: venerd� 9 febbraio 2018 16.01
A: Stefano Sofia
Cc: [hidden email]
Oggetto: Re: [R-sig-Geo] Change range of values of the legend

Hi,

Try

plot(rast, zlim = c(-5, 5))

I think the zlim argument is passed through to graphics::image() via fields::image.plot() which raster::plot() calls.  I know it isn't super obvious until until you re-read the docs about 2000 times.

Cheers,
Ben


On Feb 9, 2018, at 9:39 AM, Stefano Sofia <[hidden email]<mailto:[hidden email]>> wrote:

Dear list users,
suppose that I have this simple raster:

library(raster)
xy <- matrix(rnorm(400),20,20)
rast <- raster(xy)

plot(rast) gives me a legend with range (-3,3).
I would like to change the range of the legend to (-5,5), for example. I tried with

plot(rast, legend=FALSE, axes=FALSE)
r.range <- c(-5, 5)
plot(rast, legend.only=TRUE, axis.args=list(at=seq(r.range[1], r.range[2], 1), labels=seq(r.range[1], r.range[2], 1)))

but this does not expand the values of the legend.
Could somebody give me some hints?

Thank you
Stefano


        (oo)
--oOO--( )--OOo----------------
Stefano Sofia PhD
Area Meteorologica e  Area nivologica - Centro Funzionale
Servizio Protezione Civile - Regione Marche
Via del Colle Ameno 5
60126 Torrette di Ancona, Ancona
Uff: 071 806 7743
E-mail: [hidden email]<mailto:[hidden email]>
---Oo---------oO----------------

________________________________

AVVISO IMPORTANTE: Questo messaggio di posta elettronica pu� contenere informazioni confidenziali, pertanto � destinato solo a persone autorizzate alla ricezione. I messaggi di posta elettronica per i client di Regione Marche possono contenere informazioni confidenziali e con privilegi legali. Se non si � il destinatario specificato, non leggere, copiare, inoltrare o archiviare questo messaggio. Se si � ricevuto questo messaggio per errore, inoltrarlo al mittente ed eliminarlo completamente dal sistema del proprio computer. Ai sensi dell�art. 6 della DGR n. 1394/2008 si segnala che, in caso di necessit� ed urgenza, la risposta al presente messaggio di posta elettronica pu� essere visionata da persone estranee al destinatario.
IMPORTANT NOTICE: This e-mail message is intended to be received only by persons entitled to receive the confidential information it may contain. E-mail messages to clients of Regione Marche may contain information that is confidential and legally privileged. Please do not read, copy, forward, or store this message unless you are an intended recipient of it. If you have received this message in error, please forward it to the sender and delete it completely from your computer system.

--
This message was scanned by Libra ESVA and is believed to be clean.


[[alternative HTML version deleted]]

_______________________________________________
R-sig-Geo mailing list
[hidden email]<mailto:[hidden email]>
https://stat.ethz.ch/mailman/listinfo/r-sig-geo

Ben Tupper
Bigelow Laboratory for Ocean Sciences
60 Bigelow Drive, P.O. Box 380
East Boothbay, Maine 04544
http://www.bigelow.org<https://urlsand.esvalabs.com/?u=http%3A%2F%2Fwww.bigelow.org&e=52342f8a&h=e098bd83&f=y&p=y>

Ecocast Reports: http://seascapemodeling.org/ecocast.html<https://urlsand.esvalabs.com/?u=http%3A%2F%2Fseascapemodeling.org%2Fecocast.html&e=52342f8a&h=a906bb68&f=y&p=y>
Tick Reports: https://report.bigelow.org/tick/<https://urlsand.esvalabs.com/?u=https%3A%2F%2Freport.bigelow.org%2Ftick%2F&e=52342f8a&h=1216cd50&f=y&p=y>
Jellyfish Reports: https://jellyfish.bigelow.org/jellyfish/<https://urlsand.esvalabs.com/?u=https%3A%2F%2Fjellyfish.bigelow.org%2Fjellyfish%2F&e=52342f8a&h=6c055c4c&f=y&p=y>




--
This message has been checked by Libra Esva and is found to be clean.
Mark it as spam<http://libraesvan2.regionemarche.intra/cgi-bin/learn-msg.cgi?id=D2C0A43AAE.A432F>
Blacklist sender<http://libraesvan2.regionemarche.intra/cgi-bin/learn-msg.cgi?blacklist=1&id=D2C0A43AAE.A432F>

________________________________

AVVISO IMPORTANTE: Questo messaggio di posta elettronica pu� contenere informazioni confidenziali, pertanto � destinato solo a persone autorizzate alla ricezione. I messaggi di posta elettronica per i client di Regione Marche possono contenere informazioni confidenziali e con privilegi legali. Se non si � il destinatario specificato, non leggere, copiare, inoltrare o archiviare questo messaggio. Se si � ricevuto questo messaggio per errore, inoltrarlo al mittente ed eliminarlo completamente dal sistema del proprio computer. Ai sensi dell�art. 6 della DGR n. 1394/2008 si segnala che, in caso di necessit� ed urgenza, la risposta al presente messaggio di posta elettronica pu� essere visionata da persone estranee al destinatario.
IMPORTANT NOTICE: This e-mail message is intended to be received only by persons entitled to receive the confidential information it may contain. E-mail messages to clients of Regione Marche may contain information that is confidential and legally privileged. Please do not read, copy, forward, or store this message unless you are an intended recipient of it. If you have received this message in error, please forward it to the sender and delete it completely from your computer system.

--
This message was scanned by Libra ESVA and is believed to be clean.


        [[alternative HTML version deleted]]


_______________________________________________
R-sig-Geo mailing list
[hidden email]
https://stat.ethz.ch/mailman/listinfo/r-sig-geo
Reply | Threaded
Open this post in threaded view
|

How to label a polygon window (spatstat package)

R-sig-geo mailing list
Hi, 
I want to label a polygon (circle or polygon) inside.
As for example code 

library(spatstat)
x <- runif(20)
y <- runif(20)
X <- ppp(x, y, window=disc(0.7))
plot(X)

Now I want to label that circle inside . Can some one please help me ? 
Thanks. 

Regards.............
Tanvir Ahamed
Stockholm, Sweden     |  [hidden email]

_______________________________________________
R-sig-Geo mailing list
[hidden email]
https://stat.ethz.ch/mailman/listinfo/r-sig-geo
Reply | Threaded
Open this post in threaded view
|

Re: [R] How to label a polygon window (spatstat package)

Michael Sumner-2
Try

text(0.5, 0.5, label = "?text")

On Sat, 10 Feb 2018, 16:22 Mohammad Tanvir Ahamed via R-help, <
[hidden email]> wrote:

> Hi,
> I want to label a polygon (circle or polygon) inside.
> As for example code
>
> library(spatstat)
> x <- runif(20)
> y <- runif(20)
> X <- ppp(x, y, window=disc(0.7))
> plot(X)
>
> Now I want to label that circle inside . Can some one please help me ?
> Thanks.
>
> Regards.............
> Tanvir Ahamed
> Stockholm, Sweden     |  [hidden email]
>
> ______________________________________________
> [hidden email] mailing list -- To UNSUBSCRIBE and more, see
> https://stat.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide
> http://www.R-project.org/posting-guide.html
> and provide commented, minimal, self-contained, reproducible code.
>


--
Dr. Michael Sumner
Software and Database Engineer
Australian Antarctic Division
203 Channel Highway
Kingston Tasmania 7050 Australia

        [[alternative HTML version deleted]]

_______________________________________________
R-sig-Geo mailing list
[hidden email]
https://stat.ethz.ch/mailman/listinfo/r-sig-geo
Reply | Threaded
Open this post in threaded view
|

Re: [R] How to label a polygon window (spatstat package)

R-sig-geo mailing list
Thanks.
when there is multiple polygon , it a problem .
looking for something more .

Regards.............
Tanvir Ahamed
Stockholm, Sweden     |  [hidden email]






On Saturday, February 10, 2018, 6:35:59 AM GMT+1, Michael Sumner <[hidden email]> wrote:





Try

text(0.5, 0.5, label = "?text")

On Sat, 10 Feb 2018, 16:22 Mohammad Tanvir Ahamed via R-help, <[hidden email]> wrote:

> Hi, 
> I want to label a polygon (circle or polygon) inside.
> As for example code 
>
> library(spatstat)
> x <- runif(20)
> y <- runif(20)
> X <- ppp(x, y, window=disc(0.7))
> plot(X)
>
> Now I want to label that circle inside . Can some one please help me ? 
> Thanks. 
>
> Regards.............
> Tanvir Ahamed
> Stockholm, Sweden     |  [hidden email]
>
> ______________________________________________
> [hidden email] mailing list -- To UNSUBSCRIBE and more, see
> https://stat.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
> and provide commented, minimal, self-contained, reproducible code.
>


--
Dr. Michael Sumner
Software and Database Engineer
Australian Antarctic Division
203 Channel Highway
Kingston Tasmania 7050 Australia

_______________________________________________
R-sig-Geo mailing list
[hidden email]
https://stat.ethz.ch/mailman/listinfo/r-sig-geo
Reply | Threaded
Open this post in threaded view
|

Re: [FORGED] Re: [R] How to label a polygon window (spatstat package)

Rolf Turner

On 10/02/18 18:43, Mohammad Tanvir Ahamed via R-sig-Geo wrote:

> Thanks.
> when there is multiple polygon , it a problem .
> looking for something more .

It is not at all clear to me what you are trying to accomplish.
If it were clearer, I could probably (???) give you an idea of how to
approach your task.

Can you provide a minimal reproducible example of your situation, with a
clear explanation of what you want to do next?  Some subscribers to
r-sig-geo (myself *not* included) are very clever, but few if any are
telepathic.

cheers,

Rolf Turner

--
Technical Editor ANZJS
Department of Statistics
University of Auckland
Phone: +64-9-373-7599 ext. 88276

_______________________________________________
R-sig-Geo mailing list
[hidden email]
https://stat.ethz.ch/mailman/listinfo/r-sig-geo
Reply | Threaded
Open this post in threaded view
|

Re: [R] How to label a polygon window (spatstat package)

Marcelino de la Cruz Rot
In reply to this post by R-sig-geo mailing list
Maybe you meant something like this:


# example of several polygons (in a list)
x <- runif(20)
y <- runif(20)

polygons<- list()
for (i in 1:20) polygons[[i]]<- disc(radius=0.05, centre=c(x[i], y[i]))
plot(owin())
lapply(polygons, plot, add=T)

# label each polygon
labs<-letters
for (i in 1: length(polygons)) {xy<-centroid.owin(polygons[[i]]);
text(xy$x,xy$y, labs[i])}



Cheers,

Marcelino



El 10/02/2018 a las 6:43, Mohammad Tanvir Ahamed via R-sig-Geo escribió:

> Thanks.
> when there is multiple polygon , it a problem .
> looking for something more .
>
> Regards.............
> Tanvir Ahamed
> Stockholm, Sweden     |  [hidden email]
>
>
>
>
>
>
> On Saturday, February 10, 2018, 6:35:59 AM GMT+1, Michael Sumner <[hidden email]> wrote:
>
>
>
>
>
> Try
>
> text(0.5, 0.5, label = "?text")
>
> On Sat, 10 Feb 2018, 16:22 Mohammad Tanvir Ahamed via R-help, <[hidden email]> wrote:
>> Hi,
>> I want to label a polygon (circle or polygon) inside.
>> As for example code
>>
>> library(spatstat)
>> x <- runif(20)
>> y <- runif(20)
>> X <- ppp(x, y, window=disc(0.7))
>> plot(X)
>>
>> Now I want to label that circle inside . Can some one please help me ?
>> Thanks.
>>
>> Regards.............
>> Tanvir Ahamed
>> Stockholm, Sweden     |  [hidden email]
>>
>> ______________________________________________
>> [hidden email] mailing list -- To UNSUBSCRIBE and more, see
>> https://stat.ethz.ch/mailman/listinfo/r-help
>> PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
>> and provide commented, minimal, self-contained, reproducible code.
>>
>

--
Marcelino de la Cruz Rot
Depto. de Biología y Geología
Física y Química Inorgánica
Universidad Rey Juan Carlos
Móstoles España

_______________________________________________
R-sig-Geo mailing list
[hidden email]
https://stat.ethz.ch/mailman/listinfo/r-sig-geo
Reply | Threaded
Open this post in threaded view
|

Re: [R] How to label a polygon window (spatstat package)

R-sig-geo mailing list
Thanks. It works as expected . 
:)

Regards.............
Tanvir Ahamed
 Stockholm, Sweden     |  [hidden email]






On Saturday, February 10, 2018, 2:44:05 PM GMT+1, Marcelino de la Cruz Rot <[hidden email]> wrote:





Maybe you meant something like this:


# example of several polygons (in a list)
x <- runif(20)
y <- runif(20)

polygons<- list()
for (i in 1:20) polygons[[i]]<- disc(radius=0.05, centre=c(x[i], y[i]))
plot(owin())
lapply(polygons, plot, add=T)

# label each polygon
labs<-letters
for (i in 1: length(polygons)) {xy<-centroid.owin(polygons[[i]]);
text(xy$x,xy$y, labs[i])}



Cheers,

Marcelino



El 10/02/2018 a las 6:43, Mohammad Tanvir Ahamed via R-sig-Geo escribió:

> Thanks.
> when there is multiple polygon , it a problem .
> looking for something more .
>
> Regards.............
> Tanvir Ahamed
> Stockholm, Sweden     |  [hidden email]
>
>
>
>
>
>
> On Saturday, February 10, 2018, 6:35:59 AM GMT+1, Michael Sumner <[hidden email]> wrote:
>
>
>
>
>
> Try
>
> text(0.5, 0.5, label = "?text")
>
> On Sat, 10 Feb 2018, 16:22 Mohammad Tanvir Ahamed via R-help, <[hidden email]> wrote:
>> Hi,
>> I want to label a polygon (circle or polygon) inside.
>> As for example code
>>
>> library(spatstat)
>> x <- runif(20)
>> y <- runif(20)
>> X <- ppp(x, y, window=disc(0.7))
>> plot(X)
>>
>> Now I want to label that circle inside . Can some one please help me ?
>> Thanks.
>>
>> Regards.............
>> Tanvir Ahamed
>> Stockholm, Sweden     |  [hidden email]
>>
>> ______________________________________________
>> [hidden email] mailing list -- To UNSUBSCRIBE and more, see
>> https://stat.ethz.ch/mailman/listinfo/r-help
>> PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
>> and provide commented, minimal, self-contained, reproducible code.

>>
>

--
Marcelino de la Cruz Rot
Depto. de Biología y Geología
Física y Química Inorgánica
Universidad Rey Juan Carlos
Móstoles España

_______________________________________________
R-sig-Geo mailing list
[hidden email]
https://stat.ethz.ch/mailman/listinfo/r-sig-geo

_______________________________________________
R-sig-Geo mailing list
[hidden email]
https://stat.ethz.ch/mailman/listinfo/r-sig-geo