[R] Interactive maps

2015-04-24 Thread Antonio Serrano via R-help

 Hello, all:

   I am new here, and have a challenge to present some graphical data to the 
user in a convenient way.

   The challenge is to present a map to the user which is coloured with the 
value of a variable. Say for example, temperature. This is a preexisting graph 
that I can generate in any format, including svg. I don't have to produce it 
using R.

   When the user clicks anywhere in the map, the coordinates (longitude and 
latitude) have to be passed to R so that this, R, can look for the values of 
other variables in that location and make another graph with them.

   Does anyubody know how could I accomplish this?.

   Thanks in advance.

 

Antonio Serrano
aasde...@aim.com
ن


[[alternative HTML version deleted]]

__
R-help@r-project.org 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.

Re: [R] Interactive maps

2015-04-25 Thread Antonio Serrano via R-help

Thank you, Jim.

I didn't know the existence of the locator() function. But I can see now that I 
don't know how to read a graphic image into R to work with it.
How can I read a pre-exisiting image into R?.

Thanks again

 

 

Antonio Serrano
aasde...@aim.com
ن

 

 

-Original Message-
From: Jim Lemon 
To: Antonio Serrano 
Cc: r-help mailing list 
Sent: Sat, Apr 25, 2015 5:47 am
Subject: Re: [R] Interactive maps


Hi Antonio,
If you do create the map in R, you can use
locator().

Jim


On Sat, Apr 25, 2015 at 8:37 AM, Antonio Serrano via
R-help
 wrote:
>
>  Hello, all:
>
>I am new here,
and have a challenge to present some graphical data to the user in a convenient
way.
>
>The challenge is to present a map to the user which is coloured
with the value of a variable. Say for example, temperature. This is a
preexisting graph that I can generate in any format, including svg. I don't have
to produce it using R.
>
>When the user clicks anywhere in the map, the
coordinates (longitude and latitude) have to be passed to R so that this, R, can
look for the values of other variables in that location and make another graph
with them.
>
>Does anyubody know how could I accomplish this?.
>
>   
Thanks in advance.
>
>
>
> Antonio Serrano
> aasde...@aim.com
> ن
>
>
>
[[alternative HTML version deleted]]
>
>
__
> R-help@r-project.org 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.



[[alternative HTML version deleted]]

__
R-help@r-project.org 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.

Re: [R] Interactive maps

2015-04-27 Thread Antonio Serrano via R-help


Ok.

 
 The point now is that I have the sources (in Fortran) of the program that 
produces the graph with the map. And have to attach the information about the 
xrange and yrange to this graph in order for them to be read from R. Id est, I 
have to write: first longitude, first latitude, last longitude, last latitude, 
and also, the "figure" coordinates of the bounding box of the map in the figure.
 
 If I produce the map in eps, I can open it as a text file from the same 
fortran rogram, and modify the contents of the eps file in order to put the 
coordinates information into it.
 
 Then, once the fortran program has ended, I convert the eps to png using 
ImageMagic, because the EBImage library doesn't read eps, but png.
 
 In order for the png to contain the same properties as the eps, these have to 
be correctly defined in the eps.
 
 So, the question now is: how can I properly define properties in a eps, so 
that these are preserved in the convertion to png?.
 
 Perhaps this is not for this forum, but I haven't found information about it 
in the internet.
 


   
   
Antonio Serrano   
 aasde...@aim.com   
ن   
   
   

   
   

   
   
-Original Message-   
 From: Jim Lemon
 To: Antonio Serrano
 Sent: Sun, Apr 26, 2015 1:03 am   
 Subject: Re: [R] Interactive maps   


 
Hi Antonio,
If you mean the normalized figure coordinates (i.e. from 0 to 1)
then
you want something like
this:

loc_convert<-function(n=1,xrange=c(0,1),yrange=c(0,1)) {

plot_loc<-locator(n=n)
 plot_loc$x<-plot_loc$x/diff(xrange)+xrange[1]

plot_loc$y<-plot_loc$y/diff(yrange)+yrange[1]
 return(plot$loc)
}

where
xrange and yrange are the longitudes and latitudes respectively.

Jim


On
Sun, Apr 26, 2015 at 1:09 AM, Antonio Serrano  wrote:
> Thank
you, Jim:
>
>I have tried your suggestion and I get the following
error:
>
>   Error en rasterImage(image = "map.eps",  :
>invalid color
name 'map.eps'
>
>  I have tried with three formats of the same image: svg,
gif and eps, with
> the same result.
>
> But I have found a possible better
way to accomplish this objective in the
> following thread:
>
http://r.789695.n4.nabble.com/Loading-an-image-picture-png-jpeg-to-screen-td2244923.html
>
>
In short:
>
> library(gridExtra)
> library(EBImage)
> library(RGraphics)
>
x <- readImage("http://www.google.com/logos/teachersday09.gif";)
> g1 <-
ebimageGrob(x)
> dev.new(width=g1$width/72, height=g1$height/72)
>
plot.new()
> grid.draw(g1)
> c=locator(n=1, type="n")
>
> Then, when I click
on the map, I get the "figure" coordinates where I
> clicked, and still have to
translate these to longitude-latitude.
>
> And here comes another question:
How can I attach the first longitude, last
> longitude, fisrt latitude, last
latitude, to a JPEG, PNG or TIFF graphic?.
> These are the formats supported by
the EBImage package.
>
>
>
> Antonio Serrano
> aasde...@aim.com
>
ن
>
>
> -Original Message-
> From: Jim Lemon

> To: Antonio Serrano 
> Sent: Sat,
Apr 25, 2015 8:36 am
> Subject: Re: [R] Interactive maps
>
> Hi Antonio,
>
Try the rasterImage function.
>
> Jim
>
>
> On Sat, Apr 25, 2015 at
> 4:19
PM, Antonio Serrano  wrote:
>> Thank you, Jim.
>>
>> I
>
didn't know the existence of the locator() function. But I can see now
>> that
I
> don't know how to read a graphic image into R to work with it.
>> How can
I read
> a pre-exisiting image into R?.
>>
>> Thanks again
>>
>>
>>
Antonio Serrano
>>
> aasde...@aim.com
>> ن
>>
>>
>> -Original
Message-
>> From: Jim Lemon
> 
>> To: Antonio
Serrano 
>> Cc: r-help
> mailing list

>> Sent: Sat, Apr 25, 2015 5:47 am
>>
> Subject: Re:
[R] Interactive maps
>>
>> Hi Antonio,
>> If you do create the map
> in R,
you can use
>> locator().
>>
>> Jim
>>
>>
>> On Sat, Apr 25, 2015 at
8:37
> AM, Antonio Serrano via
>> R-help
>> 
wrote:
>>>
>>>
> Hello, all:
>>>
>>>I am new here,
>> and have a
challenge to present some
> graphical data to the user in a
>> convenient
>>
way.
>>>
>>>The challenge
> is to present a map to the user which is
coloured
>> with the value of a
> variable. Say for example, temperature. This
is a
>> preexisting graph that I
> can generate in any format, including svg.
I don't
>> have
>> to produce it
> using R.
>>>
>>>When the user clicks
anywhere in the map, the
>> coordinates
> (longitude and latitude) have to be
passed 

Re: [R] Interactive maps

2015-04-28 Thread Antonio Serrano via R-help
Thank you, Ben. I've just subscribed to R-sig-geo as you recommend. I'll post 
this staff there.
 

 

Antonio Serrano
aasde...@aim.com
ن

 

 

-Original Message-
From: Ben Tupper 
To: Antonio Serrano 
Cc: r-help 
Sent: Mon, Apr 27, 2015 7:59 pm
Subject: Re: [R] Interactive maps


Hi,

You may want to redirect your question to the R-sig-Geo mailing list:


https://stat.ethz.ch/mailman/listinfo/r-sig-geo

In the meantime, you
might consider writing to the 'rasterfile' format.  The 'rasterfile' format is
very well documented and is to read/write from R; I suspect it would easy for
you to write to this format from Fortran.  See the details
here:

http://cran.r-project.org/web/packages/raster/vignettes/rasterfile.pdf

Cheers,
Ben

On
Apr 27, 2015, at 11:55 AM, Antonio Serrano via R-help 
wrote:

> 
> 
> Ok.
> 
> 
> The point now is that I have the sources (in
Fortran) of the program that produces the graph with the map. And have to attach
the information about the xrange and yrange to this graph in order for them to
be read from R. Id est, I have to write: first longitude, first latitude, last
longitude, last latitude, and also, the "figure" coordinates of the bounding box
of the map in the figure.
> 
> If I produce the map in eps, I can open it as a
text file from the same fortran rogram, and modify the contents of the eps file
in order to put the coordinates information into it.
> 
> Then, once the
fortran program has ended, I convert the eps to png using ImageMagic, because
the EBImage library doesn't read eps, but png.
> 
> In order for the png to
contain the same properties as the eps, these have to be correctly defined in
the eps.
> 
> So, the question now is: how can I properly define properties in
a eps, so that these are preserved in the convertion to png?.
> 
> Perhaps
this is not for this forum, but I haven't found information about it in the
internet.
> 
> 
> 
> 
> 
> Antonio Serrano   
> aasde...@aim.com   
>   
ن   
> 
> 
> 
> 
> 
> 
> 
> 
> -Original Message-   
> From:
Jim Lemon
> To: Antonio Serrano   

> Sent: Sun, Apr 26, 2015 1:03 am   
> Subject: Re: [R] Interactive maps  

> 
> 
> 
> Hi Antonio,
> If you mean the normalized figure coordinates
(i.e. from 0 to 1)
> then
> you want something like
> this:
> 
>
loc_convert<-function(n=1,xrange=c(0,1),yrange=c(0,1)) {
> 
>
plot_loc<-locator(n=n)
> plot_loc$x<-plot_loc$x/diff(xrange)+xrange[1]
> 
>
plot_loc$y<-plot_loc$y/diff(yrange)+yrange[1]
> return(plot$loc)
> }
> 
>
where
> xrange and yrange are the longitudes and latitudes respectively.
> 
>
Jim
> 
> 
> On
> Sun, Apr 26, 2015 at 1:09 AM, Antonio Serrano
 wrote:
>> Thank
> you, Jim:
>> 
>>   I have tried your
suggestion and I get the following
> error:
>> 
>>  Error en
rasterImage(image = "map.eps",  :
>>   invalid color
> name 'map.eps'
>> 
>>
I have tried with three formats of the same image: svg,
> gif and eps, with
>>
the same result.
>> 
>> But I have found a possible better
> way to
accomplish this objective in the
>> following thread:
>> 
>
http://r.789695.n4.nabble.com/Loading-an-image-picture-png-jpeg-to-screen-td2244923.html
>>

>> 
> In short:
>> 
>> library(gridExtra)
>> library(EBImage)
>>
library(RGraphics)
>> 
> x <-
readImage("http://www.google.com/logos/teachersday09.gif";)
>> g1 <-
>
ebimageGrob(x)
>> dev.new(width=g1$width/72, height=g1$height/72)
>> 
>
plot.new()
>> grid.draw(g1)
>> c=locator(n=1, type="n")
>> 
>> Then, when I
click
> on the map, I get the "figure" coordinates where I
>> clicked, and
still have to
> translate these to longitude-latitude.
>> 
>> And here comes
another question:
> How can I attach the first longitude, last
>> longitude,
fisrt latitude, last
> latitude, to a JPEG, PNG or TIFF graphic?.
>> These are
the formats supported by
> the EBImage package.
>> 
>> 
>> 
>> Antonio
Serrano
>> aasde...@aim.com
>> 
> ن
>> 
>> 
>> -Original
Message-
>> From: Jim Lemon
> 
>> To: Antonio
Serrano 
>> Sent: Sat,
> Apr 25, 2015 8:36 am
>> Subject:
Re: [R] Interactive maps
>> 
>> Hi Antonio,
>> 
> Try the rasterImage
function.
>> 
>> Jim
>> 
>> 
>> On Sat, Apr 25, 2015 at
>> 4:19
> PM,
Antonio Serrano  wrote:
>>> Thank you, Jim.
>>> 
>>> I
>>

> didn't know the existence of the locator() function. But I can

Re: [R] Plotting legend outside of chart area

2015-06-25 Thread Antonio Serrano via R-help
First, you have to increase the bottom margin to have enough space for the 
legend.
You do it like this:
par(
mar = c(6,4,4,2)
)

>From R help:
 ‘mar’ A numerical vector of the form ‘c(bottom, left, top, right)’
  which gives the number of lines of margin to be specified on
  the four sides of the plot.  The default is ‘c(5, 4, 4, 2) +
  0.1’.
So, we have increased the first number from 5 to 6 to have mor space at the 
bottom.

Then, in the legend(), you have to add the option:
inset = c(0, -0.2),

>From R help:
   inset: inset distance(s) from the margins as a fraction of the plot
  region when legend is placed by keyword.
Change the -0.2 and the 6 in the par(mar) until you get a nice chart

 

 

Antonio Serrano
aasde...@aim.com
ن

 

 

-Original Message-
From: Samantha Allcock 
To: 'r-help@r-project.org' 
Sent: Wed, Jun 24, 2015 10:08 pm
Subject: [R] Plotting legend outside of chart area


Hello,

I am trying to add a legend to my PCA plot so that it looks neat. I
think plotting this outside of the chart area would be good but I cannot seem to
fathom the correct code for this. I wondered if anyone could help please?

The
code I am using is as follows:

grp<- with(Matan, cut(R_category_no,14,
labels=1:14))
cols <- c("grey0", "wheat", "red", "cyan", "orange",
"darkolivegreen2", "purple3",
"royalblue", "burlywood4", "orchid",
"forestgreen", "green",
"gray", "yellow1")
plot(geopca, display="sites",
scaling=3, type="n")
points(geopca, display="sites", scaling=3, col=cols[grp],
pch=16)

legend("bottomright", col=c("grey0", "wheat", "red", "cyan",
"orange", "darkolivegreen2",
"purple3", "royalblue", "burlywood4", "orchid",
"forestgreen", "green",
"gray", "yellow1"), c("Control type 1", "Control type
2",
"External/Courtyard", "Midden", "Animal Occupation",
"External fire
installations and ashy deposits",
"Internal fire installations and ashy
deposits", "Hearth make-up",
"Floors and surfaces", "Plasters and clay
features", "Storage features",
"Platforms and benches", "Mortars", "Roofs and
roofing materials"), pch=16,
cex=0.75, bty="n")

Thank you for your time in
advance


Dr Samantha Lee Allcock
Faculty of Science and
Technology
Department of Archaeology, Anthropology and Forensic
Science
Christchurch House Rm: C133
Bournemouth University
Talbot
Campus
Poole
BH12 5BB
Tel: 01202
9(62474)

sallc...@bournemouth.ac.uk
research.bournemouth.ac.uk/2014/07/inea-project-2


BU
is a Disability Two Ticks Employer and has signed up to the Mindful Employer
charter. Information about the accessibility of University buildings can be
found on the BU DisabledGo webpages This email is intended only for the person
to whom it is addressed and may contain confidential information. If you have
received this email in error, please notify the sender and delete this email,
which must not be copied, distributed or disclosed to any other person. Any
views or opinions presented are solely those of the author and do not
necessarily represent those of Bournemouth University or its subsidiary
companies. Nor can any contract be formed on behalf of the University or its
subsidiary companies via email.

[[alternative HTML version
deleted]]

__
R-help@r-project.org
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.



[[alternative HTML version deleted]]

__
R-help@r-project.org 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.

Re: [R] Plotting legend outside of chart area

2015-06-26 Thread Antonio Serrano via R-help
First, you have to increase the bottom margin to have enough space for the 
legend.
 You do it like this:
 par(
 mar = c(6,4,4,2)
 )
 
 From R help:
  ‘mar’ A numerical vector of the form ‘c(bottom, left, top, right)’
   which gives the number of lines of margin to be specified on
   the four sides of the plot.  The default is ‘c(5, 4, 4, 2) +
   0.1’.
 So, we have increased the first number from 5 to 6 to have mor space at the 
bottom.
 
 Then, in the legend(), you have to add the option:
 inset = c(0, -0.2),
 
 From R help:
inset: inset distance(s) from the margins as a fraction of the plot
   region when legend is placed by keyword.
 Change the -0.2 and the 6 in the par(mar) until you get a nice chart


   
   

 

 

Antonio Serrano
aasde...@aim.com
ن

 

 

-Original Message-
From: Samantha Allcock 
To: 'r-help@r-project.org' 
Sent: Wed, Jun 24, 2015 10:08 pm
Subject: [R] Plotting legend outside of chart area


Hello,

I am trying to add a legend to my PCA plot so that it looks neat. I
think plotting this outside of the chart area would be good but I cannot seem to
fathom the correct code for this. I wondered if anyone could help please?

The
code I am using is as follows:

grp<- with(Matan, cut(R_category_no,14,
labels=1:14))
cols <- c("grey0", "wheat", "red", "cyan", "orange",
"darkolivegreen2", "purple3",
"royalblue", "burlywood4", "orchid",
"forestgreen", "green",
"gray", "yellow1")
plot(geopca, display="sites",
scaling=3, type="n")
points(geopca, display="sites", scaling=3, col=cols[grp],
pch=16)

legend("bottomright", col=c("grey0", "wheat", "red", "cyan",
"orange", "darkolivegreen2",
"purple3", "royalblue", "burlywood4", "orchid",
"forestgreen", "green",
"gray", "yellow1"), c("Control type 1", "Control type
2",
"External/Courtyard", "Midden", "Animal Occupation",
"External fire
installations and ashy deposits",
"Internal fire installations and ashy
deposits", "Hearth make-up",
"Floors and surfaces", "Plasters and clay
features", "Storage features",
"Platforms and benches", "Mortars", "Roofs and
roofing materials"), pch=16,
cex=0.75, bty="n")

Thank you for your time in
advance


Dr Samantha Lee Allcock
Faculty of Science and
Technology
Department of Archaeology, Anthropology and Forensic
Science
Christchurch House Rm: C133
Bournemouth University
Talbot
Campus
Poole
BH12 5BB
Tel: 01202
9(62474)

sallc...@bournemouth.ac.uk
research.bournemouth.ac.uk/2014/07/inea-project-2


BU
is a Disability Two Ticks Employer and has signed up to the Mindful Employer
charter. Information about the accessibility of University buildings can be
found on the BU DisabledGo webpages This email is intended only for the person
to whom it is addressed and may contain confidential information. If you have
received this email in error, please notify the sender and delete this email,
which must not be copied, distributed or disclosed to any other person. Any
views or opinions presented are solely those of the author and do not
necessarily represent those of Bournemouth University or its subsidiary
companies. Nor can any contract be formed on behalf of the University or its
subsidiary companies via email.

[[alternative HTML version
deleted]]

__
R-help@r-project.org
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.



[[alternative HTML version deleted]]

__
R-help@r-project.org 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.