Presentation Geoxp
Presentation Geoxp
(version 1.5.0)
T. Laurent*, A. Ruiz-Gazen†and C. Thomas-Agnan‡
Toulouse School of Economics
February 5, 2018
Presently, GeoXp draws a map, considering spatial units like points: a spatial unit
is defined geographically by two scalars x and y. Indeed, for drawing a map, the spa-
tial coordinates of spatial units have been extracted from sp.obj by using the function
coordinates, which can be applied on to any Spatial Class object (SpatialPointsDataFrame,
SpatialPolygonsDataFrame, etc).
It also prints a statistical graphic. The variable(s) of interest are given by name.var
or names.var, a (vector of) character (or numeric) which indicates the column(s) of
the sp.obj@data to be used in the analysis. The sp.obj@data is by construction, a
* [email protected]
† [email protected]
‡ [email protected]
1 The non interactive functions included in GeoXp correspond to internal or wrap functions
1
data.frame.
In the function call, the ... correspond to specificities of each function (more details
in 3). For example, it could indicate the number of bars for a histogram, if the y-axis
should represent or not the count or the percent for a barplot, etc....
Finally, options are common to most of the functions (with some small specificities
by function) and described in the following section. Let us start with a simple example.
As we can see above, this data set is a data.frame containing the spatial coordinates
of the cities in the variables longitude and latitude. It also contains several vari-
ables corresponding to the city names, the selling and renting prices, etc...
The first operation consists in creating a Spatial Object. First, we have to create a
SpatialPoints object by specifying a 2 × d matrix with longitude and latitude:
> immob.sp <- SpatialPoints(cbind(immob$longitude, immob$latitude))
> class(immob.sp)
[1] "SpatialPoints"
attr(,"package")
[1] "sp"
Finally, we can call the function histomap by giving as first argument, the Spatial
Object and as second argument, we give a character (it can also be the number of the
column, here the value 6) which corresponds to the name of the variable of interest. It
results in the opening of a Tk window and two devices, a device with number 2 which
corresponds to the map and a device with number 3 corresponding to the statistical
graph, in this case, the histogram:
2
> histomap(immob.spdf, "prix.vente")
As we can see in the Fig. ??, the Tk window contains several buttons that the user can
click on: the user may select a point (Point button) or a polygon (Polygon button)
on the map and may also select a bar on the histogram (Cell button). In this example,
the user may also print bubbles by clicking on Bubbles after choosing a numerical
variable among the variables included in the Spatial object.
Most of these options are common to all functions. It can differ depending on the
function, but the principles remain the same.
3
SpatialPointsDataFrame, the user may specify by using the carte option,
a matrix with 2 columns for drawing spatial polygonal contours: x and y co-
ordinates of the vertices of the polygon. The functions polylist2list() and
spdf2list() convert some spatial objects (Polylist and SpatialPolygonDataFrame)
into matrices as decribed above to draw a background map.
• identify: if TRUE, the names of selected sites will be printed on the map. The
names of spatial units correpond to row.names of the attribute table row.names(sp.obj@data).
• cex.lab: a numeric value, it gives the character size of labels
• pch: 16 by default, it gives the symbol for selected points
• col: "lightblue3" by default, it gives the color of the bars of a histogram, the
points of a scatter plot, etc... In the case where the variable of interest is a factor,
the user may give a vector of colors corresponding to the colors of each level to
be printed on the map.
• xlab: a character, title for the graphic x-axis
• lablat: a character, name of the y-axis that will be printed on the map
4
In the following code, the option nbcol=15 and type = "percent" are specific
to the function histomap. The first one indicates the number of bars to draw and
the second the fact that the y-axis of the graphic should represent the percentage of
individuals. Notice that the variable of interest corresponds here to the 7th variable of
the sp.obj, i.e. the variation of selling price observed between 2007 and 2008.
> histomap(immob.spdf, 7, nbcol = 15, type = "percent",
+ names.attr = names(immob), criteria = criteria, carte = cont_midiP,
+ identify = TRUE, cex.lab = 0.5, pch = 12, col = "pink",
+ xlab = "variation price", ylab = "percent", axes = TRUE, lablong = "x",
+ lablat = "y")
On Fig. ??, we have represented the two devices after selecting the bars with high val-
ues of the variable of interest, clicking on the Bubbles button (and choosing the vari-
able prix.vente, average selling price) and clicking on the Preselected sites
button.
The result on the map and on the graphic is that the selected spatial units are represented
in red. Besides on the map, the sites have different sizes depending on the values taken
by prix.vente and there is a green croice for the cities of the North.
If the user clicks on the Save results button, he obtains the following message and
can use the last.select object thus created:
[1] "Results have been saved in last.select object"
> last.select
[1] 12 18 24 31 32 37 39 42 49 67 73 74 79 81 84
• barmap: bar plot (vertical bar) of the given factor variable name.var. Specific
options are type to specify the type of the value on the y-axis (count or percent)
and names.arg to specify the names of levels of name.var.
5
• driftmap: the device is divided into 2 rows and 2 columns which contains :
– cell 1:the selected sites divided into m rows and q columns (m and q are
selected with the tk window),
– cell 2: a scatter plot with coordinates(sp.obj)[,2] on the x-axis and
the mean and median of name.var calculated for the m rows on the y-axis,
– cell 3: a scatter plot with the mean and median of name.var calculated for
the q columns in x-axis and coordinates(sp.obj)[,1] in y-axis,
– cell 4: a legend indicating the direction of the North. Specific options are
name.var, interpol=TRUE, nuage=TRUE, lty=1:2, cex=0.7 (see the
help of the function for more details).
• ginimap: Lorentz curve from name.var and calculates the Gini Index associ-
ated to name.var.
• histomap: histogram of a given variable name.var. Specific options are nbcol
for the number of bars and type for the values to print on the y-axis (count,
percent or density)
• histobarmap: bar plot (vertical bar) of the given variable names.var[1] and
histogram of the given variable names.var[2]. Specific options are type and
names.arg.
6
• plot3dmap: 3d-plot of three given variables names.var. Specific options are
box for drawing a cube and zlab. It depends on the package rgl.
The two functions barnbmap and histnbmap analyse a spatial neigborhood structure
and have not a name.var argument.
7
3.4 Other dependencies
The quantile spline regression drawn on the scatterplot with option quantiles comes
from the function qsreg included in the fields package. The splancs package is called
for the use of the inout function.
With GeoXp, the function makeneighborsw builds a spatial weight matrix by using
both methods of the nearest neighbors and the threshold distance. However, the result
is included in a matrix object and the user will have to convert this object into an nb
object by using the function mat2listw, as follows:
> W2.matrix <- makeneighborsw(cbind(immob$longitude, immob$latitude),
+ method = "both", m = 5, d = 175000)
> W2.nb <- mat2listw(W2.matrix)$neighbours
> class(W2.nb)
[1] "nb"
Note that the functions histnbmap and barnbmap included in GeoXp allow an inter-
active exploratory analysis of the neighborhood structure given by an nb object.
8
reverse.
In this case, when the user selects the Save result button, it creates in the last.select
object a matrix containing the couples of selected sites:
[1] "Results have been saved in last.select object"
> last.select
[,1] [,2]
[1,] 3 17
[2,] 3 38
[3,] 3 39
[4,] 3 40
[5,] 3 63
[6,] 3 70
[7,] 3 90
[8,] 85 53
[9,] 85 58
[10,] 85 65
[11,] 85 66
[12,] 85 73