shapefiles plotting and colouring

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

shapefiles plotting and colouring

Paolo Cavallini
-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

Hi all.
it may be a silly question, but: how can I, after reading a shapefile with the
appropriate library, draw them with different colours (or grey shades)
according to different database fields (read through RODBC)? The idea is
similar to the polygon command, but using shp as polygons and database fields
as qualifiers.
Thanks for any suggestions.
Ciao.
paolo
- --
Paolo Cavallini
cavallini at faunalia.it
www.faunalia.it
Piazza Garibaldi 5
56025 Pontedera (PI)
Italy
Tel: (+39)348-3801953
GPG signature/firma digitale @:
www.faunalia.it/Public_key_Paolo.asc
- ------------------------------------------
Lavoro esclusivamente con software libero.
I use exclusively free software.
www.gnu.org / www.linux.org
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.2.3 (GNU/Linux)

iD8DBQE/onhL/NedwLUzIr4RAoTVAKCzgD0WU5awJxg0gS37HD64WVF9uwCgmDYx
UhPvLWUMPaJMNeA4NIuNPg8=
=f7Fk
-----END PGP SIGNATURE-----



Reply | Threaded
Open this post in threaded view
|

shapefiles plotting and colouring

Christophe Declercq
Hi, Paolo

> De : r-sig-geo-bounces at stat.math.ethz.ch
> [mailto:r-sig-geo-bounces at stat.math.ethz.ch]De la part de Paolo
> Cavallini
> Envoy? : vendredi 31 octobre 2003 14:57
> ? : r-sig-geo at stat.math.ethz.ch
> Objet : [R-sig-Geo] shapefiles plotting and colouring

[...]
> Hi all.
> it may be a silly question

Not silly at all...

> it may be a silly question, but: how can I, after reading a
> shapefile with the
> appropriate library, draw them with different colours (or grey shades)
> according to different database fields (read through RODBC)? The idea is
> similar to the polygon command, but using shp as polygons and
> database fields
> as qualifiers.

In the 'maptools' package, you have the 'plot.Map' function (see ?plot.Map
and the 'auxvar', 'type' and 'nclass' arguments).

If you convert from a 'Map' object to a 'polylist' object with the
'Map2poly' function, you can also use 'plotpolys' which is more flexible.

Have a look at the ?plotpolys example, and by the way, try also the
'RColorBrewer' package for beautiful and efficient colors.

Hope it helps.

Christophe
--
Christophe DECLERCQ, MD
Observatoire R?gional de la Sant? Nord-Pas-de-Calais
13, rue Faidherbe 59046 LILLE Cedex FRANCE
Phone +33 3 20 15 49 24
Fax   +33 3 20 55 92 30
E-mail c.declercq at orsnpdc.org

> Thanks for any suggestions.
> Ciao.
> paolo
> - --
> Paolo Cavallini
> cavallini at faunalia.it
> www.faunalia.it
> Piazza Garibaldi 5
> 56025 Pontedera (PI)
> Italy
> Tel: (+39)348-3801953
> GPG signature/firma digitale @:
> www.faunalia.it/Public_key_Paolo.asc

[...]



Reply | Threaded
Open this post in threaded view
|

shapefiles plotting and colouring

hi_ono2001
In reply to this post by Paolo Cavallini
Hi.

I've tried to draw choropleth maps by rmap package as follows.

library(rmap)

mySF <- shapefile("columbus.shp")

 crime <- mySF$CRIME

# user-defined legend
 classes <- c(50,100,500,1000,5000)
 breaks <- length(classes) + 1
 classNo <- crime < classes[1]
 for(i in 1:(breaks - 1))
   classNo <- classNo + (crime >= classes[i] & crime < classes[i + 1]) * i

 classNo <- classNo + (crime >= max(classes)) * breaks
 plot(mySF, f=gray(1 - classNo/breaks)) # draw map
 lines(mySF, col="red") # draw outlines

----- Original Message -----
From: "Paolo Cavallini" <cavallini at faunalia.it>
To: <r-sig-geo at stat.math.ethz.ch>
Sent: Friday, October 31, 2003 11:57 PM
Subject: [R-sig-Geo] shapefiles plotting and colouring


> -----BEGIN PGP SIGNED MESSAGE-----
> Hash: SHA1
>
> Hi all.
> it may be a silly question, but: how can I, after reading a shapefile with
the
> appropriate library, draw them with different colours (or grey shades)
> according to different database fields (read through RODBC)? The idea is
> similar to the polygon command, but using shp as polygons and database
fields
> as qualifiers.
> Thanks for any suggestions.
> Ciao.
> paolo



Reply | Threaded
Open this post in threaded view
|

shapefiles plotting and colouring

Paolo Cavallini
-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

Thanks for this. My problem is, however, to use variables from a database
(PostgreSQL in our case) rather than those of the dbf associated with the shp
file.
All the best.
Paolo

At 18:03, venerd? 31 ottobre 2003 you presumably wrote:

> Hi.
>
> I've tried to draw choropleth maps by rmap package as follows.
>
> library(rmap)
>
> mySF <- shapefile("columbus.shp")
>
>  crime <- mySF$CRIME
>
> # user-defined legend
>  classes <- c(50,100,500,1000,5000)
>  breaks <- length(classes) + 1
>  classNo <- crime < classes[1]
>  for(i in 1:(breaks - 1))
>    classNo <- classNo + (crime >= classes[i] & crime < classes[i + 1]) * i
>
>  classNo <- classNo + (crime >= max(classes)) * breaks
>  plot(mySF, f=gray(1 - classNo/breaks)) # draw map
>  lines(mySF, col="red") # draw outlines
>
> ----- Original Message -----
> From: "Paolo Cavallini" <cavallini at faunalia.it>
> To: <r-sig-geo at stat.math.ethz.ch>
> Sent: Friday, October 31, 2003 11:57 PM
> Subject: [R-sig-Geo] shapefiles plotting and colouring
>
> > -----BEGIN PGP SIGNED MESSAGE-----
> > Hash: SHA1
> >
> > Hi all.
> > it may be a silly question, but: how can I, after reading a shapefile
> > with
>
> the
>
> > appropriate library, draw them with different colours (or grey shades)
> > according to different database fields (read through RODBC)? The idea is
> > similar to the polygon command, but using shp as polygons and database
>
> fields
>
> > as qualifiers.
> > Thanks for any suggestions.
> > Ciao.
> > paolo

- --
Paolo Cavallini
cavallini at faunalia.it
www.faunalia.it
Piazza Garibaldi 5
56025 Pontedera (PI)
Italy
Tel: (+39)348-3801953
GPG signature/firma digitale @:
www.faunalia.it/Public_key_Paolo.asc
- ------------------------------------------
Lavoro esclusivamente con software libero.
I use exclusively free software.
www.gnu.org / www.linux.org
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.2.3 (GNU/Linux)

iD8DBQE/opuc/NedwLUzIr4RApSMAJoCktLlzZVBfzStI09vsNKScgDk4wCdHNz8
+HhE2grymbl4Z5S84M2Fwgo=
=4H68
-----END PGP SIGNATURE-----



Reply | Threaded
Open this post in threaded view
|

shapefiles plotting and colouring

Danlin Yu-2
Hi, Paolo:
    I don't know if this helps. Indeed, if you have access to ArcGIS or
ArcView, I would surely suggest you to *join* your other database fields
to the shapefile and export the joined shapefile as a new one, then I
suppose either Chris or Hisaji's method will work for your problem.

On Fri, 31 Oct 2003, Paolo Cavallini wrote:

> -----BEGIN PGP SIGNED MESSAGE-----
> Hash: SHA1
>
> Thanks for this. My problem is, however, to use variables from a database
> (PostgreSQL in our case) rather than those of the dbf associated with the shp
> file.
> All the best.
> Paolo
>
> At 18:03, venerd? 31 ottobre 2003 you presumably wrote:
> > Hi.
> >
> > I've tried to draw choropleth maps by rmap package as follows.
> >
> > library(rmap)
> >
> > mySF <- shapefile("columbus.shp")
> >
> >  crime <- mySF$CRIME
> >
> > # user-defined legend
> >  classes <- c(50,100,500,1000,5000)
> >  breaks <- length(classes) + 1
> >  classNo <- crime < classes[1]
> >  for(i in 1:(breaks - 1))
> >    classNo <- classNo + (crime >= classes[i] & crime < classes[i + 1]) * i
> >
> >  classNo <- classNo + (crime >= max(classes)) * breaks
> >  plot(mySF, f=gray(1 - classNo/breaks)) # draw map
> >  lines(mySF, col="red") # draw outlines
> >
> > ----- Original Message -----
> > From: "Paolo Cavallini" <cavallini at faunalia.it>
> > To: <r-sig-geo at stat.math.ethz.ch>
> > Sent: Friday, October 31, 2003 11:57 PM
> > Subject: [R-sig-Geo] shapefiles plotting and colouring
> >
> > > -----BEGIN PGP SIGNED MESSAGE-----
> > > Hash: SHA1
> > >
> > > Hi all.
> > > it may be a silly question, but: how can I, after reading a shapefile
> > > with
> >
> > the
> >
> > > appropriate library, draw them with different colours (or grey shades)
> > > according to different database fields (read through RODBC)? The idea is
> > > similar to the polygon command, but using shp as polygons and database
> >
> > fields
> >
> > > as qualifiers.
> > > Thanks for any suggestions.
> > > Ciao.
> > > paolo
>
> - --
> Paolo Cavallini
> cavallini at faunalia.it
> www.faunalia.it
> Piazza Garibaldi 5
> 56025 Pontedera (PI)
> Italy
> Tel: (+39)348-3801953
> GPG signature/firma digitale @:
> www.faunalia.it/Public_key_Paolo.asc
> - ------------------------------------------
> Lavoro esclusivamente con software libero.
> I use exclusively free software.
> www.gnu.org / www.linux.org
> -----BEGIN PGP SIGNATURE-----
> Version: GnuPG v1.2.3 (GNU/Linux)
>
> iD8DBQE/opuc/NedwLUzIr4RApSMAJoCktLlzZVBfzStI09vsNKScgDk4wCdHNz8
> +HhE2grymbl4Z5S84M2Fwgo=
> =4H68
> -----END PGP SIGNATURE-----
>
> _______________________________________________
> R-sig-Geo mailing list
> R-sig-Geo at stat.math.ethz.ch
> https://www.stat.math.ethz.ch/mailman/listinfo/r-sig-geo
>

    Sincerely,
    Danlin Yu, Ph.D. Candidate
    Department of Geography
    University of Wisconsin, Milwaukee
    Tel: (414)229-5818
    Fax: (414)229-3981
    Email: danlinyu at uwm.edu



Reply | Threaded
Open this post in threaded view
|

shapefiles plotting and colouring

Roger Bivand
Administrator
In reply to this post by Paolo Cavallini
Paolo:

The key question will be to make sure that the colours you use to fill the
polygons are in the correct order for the polygons. If you use Map2poly()
to convert the shapes of a Map object to a polylist, you will see that you
can attach a "region.id" attribute. When you access your database records,
you could use that to check, and if necessary re-order the data frame rows
using match(), to put them in the same order as the spatial objects (which
can be multiple polygons).

Then if your variable is a factor, you need to assign colours to its
levels, if continuous, you need to choose and impose class intervals to
use colour table lookup in the col= argument to plotpolys. Try running
example(plotpolys), and then just type for example cols[np] to see how the
table lookup is being used to feed a vector of colours of the same length
as mappolys to the function. The results of length(mappolys) and
length(cols[np]) should be the same. But I do recommend checking the
"region.id" against your database!

Hope this helps,

Roger


On Fri, 31 Oct 2003, Paolo Cavallini wrote:

> -----BEGIN PGP SIGNED MESSAGE-----
> Hash: SHA1
>
> Thanks for this. My problem is, however, to use variables from a database
> (PostgreSQL in our case) rather than those of the dbf associated with the shp
> file.
> All the best.
> Paolo
>
> At 18:03, venerd? 31 ottobre 2003 you presumably wrote:
> > Hi.
> >
> > I've tried to draw choropleth maps by rmap package as follows.
> >
> > library(rmap)
> >
> > mySF <- shapefile("columbus.shp")
> >
> >  crime <- mySF$CRIME
> >
> > # user-defined legend
> >  classes <- c(50,100,500,1000,5000)
> >  breaks <- length(classes) + 1
> >  classNo <- crime < classes[1]
> >  for(i in 1:(breaks - 1))
> >    classNo <- classNo + (crime >= classes[i] & crime < classes[i + 1]) * i
> >
> >  classNo <- classNo + (crime >= max(classes)) * breaks
> >  plot(mySF, f=gray(1 - classNo/breaks)) # draw map
> >  lines(mySF, col="red") # draw outlines
> >
> > ----- Original Message -----
> > From: "Paolo Cavallini" <cavallini at faunalia.it>
> > To: <r-sig-geo at stat.math.ethz.ch>
> > Sent: Friday, October 31, 2003 11:57 PM
> > Subject: [R-sig-Geo] shapefiles plotting and colouring
> >
> > > -----BEGIN PGP SIGNED MESSAGE-----
> > > Hash: SHA1
> > >
> > > Hi all.
> > > it may be a silly question, but: how can I, after reading a shapefile
> > > with
> >
> > the
> >
> > > appropriate library, draw them with different colours (or grey shades)
> > > according to different database fields (read through RODBC)? The idea is
> > > similar to the polygon command, but using shp as polygons and database
> >
> > fields
> >
> > > as qualifiers.
> > > Thanks for any suggestions.
> > > Ciao.
> > > paolo
>
> - --
> Paolo Cavallini
> cavallini at faunalia.it
> www.faunalia.it
> Piazza Garibaldi 5
> 56025 Pontedera (PI)
> Italy
> Tel: (+39)348-3801953
> GPG signature/firma digitale @:
> www.faunalia.it/Public_key_Paolo.asc
> - ------------------------------------------
> Lavoro esclusivamente con software libero.
> I use exclusively free software.
> www.gnu.org / www.linux.org
> -----BEGIN PGP SIGNATURE-----
> Version: GnuPG v1.2.3 (GNU/Linux)
>
> iD8DBQE/opuc/NedwLUzIr4RApSMAJoCktLlzZVBfzStI09vsNKScgDk4wCdHNz8
> +HhE2grymbl4Z5S84M2Fwgo=
> =4H68
> -----END PGP SIGNATURE-----
>
> _______________________________________________
> R-sig-Geo mailing list
> R-sig-Geo at stat.math.ethz.ch
> https://www.stat.math.ethz.ch/mailman/listinfo/r-sig-geo
>

--
Roger Bivand
Economic Geography Section, Department of Economics, Norwegian School of
Economics and Business Administration, Breiviksveien 40, N-5045 Bergen,
Norway. voice: +47 55 95 93 55; fax +47 55 95 93 93
e-mail: Roger.Bivand at nhh.no



Roger Bivand
Department of Economics
Norwegian School of Economics
Helleveien 30
N-5045 Bergen, Norway