How to use R to plot 3D graph with zip maps from Arcview on X-Y plane?
What you need on your computer
Arcview
R 1.7.1 for Windows
How to do it?
If the Arcview shape files' table file ( .dbf ) does not
have columns containing
x,y coordinates, i.e. when you open the shape file in Arcview, the
attribute table does not have x,y coordinates as attributes, then you
need to
- Open .shp in Arcview
- Click Scripts in Table of contents,
i.e. the window with icons of Views, Tables, Charts, Layouts
, and Scripts listed vertically. Then click New
in the upper of the window to pop out a new Script1
window.
- Now choose Load text files... from Script
menu. In the new popout Load Script
window, go to diretory of samples/scripts under
the folder of Arcview. In my computer, it's c:/esri/av_gis30
/arcview, choose file addxycoo.ave in the File Name
, click OK to load it. Now addxycoo.ave
appears in the Script 1 window.
- Click the Nike symbol icon to compile addxycoo.ave
- Click the icon of a running person to run the code, the window
blinks and now 2 columns with the name X-coord and
Y-coord is written into the table file .dbf .
You can check by clicking Table... in
Theme menu to check it.
Close Arcview and open R 1.7.1
Choose Install package(s) from CRAN... from
Packages, select shapefiles and
scatterplot3d from the select window,
click OK
Download plot3d.r and follow the
comments in plot3d.r to make some minor changes of
input and output folders
Run plot3d.r in R Console by type in
source("path of plot3d.r/plot3d.r"), then the 3D plot
plot3d.ps
will be generated in the folder where you specified in
plot3d.r
Remarks:
The shapefiles has to be in polygons or points to support the
addxycoo.ave
Before running addxycoo.ave, make sure that the data is the
active theme and the view is the last active window before returning
to the Script window. This is because the code
calls theView = av.GetActiveDoc, and Arcview takes
the last active winodw before returning to Script
window to be the active window
I'm using Windows R because it has a more convenient tool to update
packages
Example
This example illustrates how to get that 3D plot using Rochester county map.
Download shape files for Rochester county and save under c:/.
- Open theme1.shp in Arcview
- Click Scripts in Table of contents,
Then click New
in the upper of the window to pop out a new Script1
window.
- Now choose Load text files... from Script
menu. In the new popout Load Script
window, go to diretory of samples/scripts under
the folder of Arcview. You can get the full path of Arcview by
simply point your mouse to Arcview shortcut icon and stay for
a while. In my computer, it's c:/esri/av_gis30
/arcview, choose file addxycoo.ave in the File Name
, click OK to load it. Now addxycoo.ave
appears in the Script 1 window.
- Click the Nike symbol icon to compile addxycoo.ave
- Click the icon of a running person to run the code, the window
blinks and now 2 columns with the name X-coord and
Y-coord is written into the table file theme1.dbf
.
Check by clicking Table... in
Theme menu or open theme1.dbf.
Close Arcview and open R 1.7.1
Choose Install package(s) from CRAN... from
Packages, select shapefiles and
scatterplot3d from the select window,
click OK
Download plot3d.r to
M:/public_html/PLOT3D
Run plot3d.r in R Console by type in
source("M:/public_html/PLOT3D/plot3d.r"), then the 3D plot
plot3d.ps
will be generated under M:/public_html/PLOT3D
Another Example
This example illustrates how to get that 3D plot using Minnesota county map.
Download shape files for Minnesota county and save under c:/.
- Open minnesota.shp in Arcview
- Click Scripts in Table of contents,
Then click New
in the upper of the window to pop out a new Script1
window.
- Now choose Load text files... from Script
menu. In the new popout Load Script
window, go to diretory of samples/scripts under
the folder of Arcview. You can get the full path of Arcview by
simply point your mouse to Arcview shortcut icon and stay for
a while. In my computer, it's c:/esri/av_gis30
/arcview, choose file addxycoo.ave in the File Name
, click OK to load it. Now addxycoo.ave
appears in the Script 1 window.
- Click the Nike symbol icon to compile addxycoo.ave
- Click the icon of a running person to run the code, the window
blinks and now 2 columns with the name X-coord and
Y-coord is written into the table file theme1.dbf
.
Check by clicking Table... in
Theme menu or open minnesota.dbf.
Close Arcview and open R 1.7.1
Choose Install package(s) from CRAN... from
Packages, select shapefiles and
scatterplot3d from the select window,
click OK
Download plot3dmn.r to
M:/public_html/PLOT3D
Run plot3dmn.r in R Console by type in
source("M:/public_html/PLOT3D/plot3dmn.r"), then the 3D plot
plot3dmn.ps
will be generated under M:/public_html/PLOT3D
Remark:
To save space, the minnesota.dbf downloaded from above link has
already the X-coord and Y-coord columns inside. You can simply
open it in Excel to delete them. It won't cause problem when you open
the minnesota.shp in Arcview.
What I found here is that after submittimg
source("M:/public_html/PLOT3D/plot3dmn.r")
in R, when you open the generated plot3dmn.ps in gsview32 or
some other software, you may find that the 3D plot is incomplete, there may
be some zips or counties missing. Now you need to close R to let R write its
buffer to the .ps file to make it complete.