One of the interesting things about having a blog are the comments and emails that you receive. In the previous posting, I demonstrated how you can use the Bridge to R and R graphics to create histograms and contour plots that rivals anything that SAS/Graph can do. Well, I received an email from a long lost soul who I worked with in Michigan for about a year on a banking project. He asked, "But can it do the Cowboy Hat?"
That made me laugh out loud and brought back a lot of memories. David and I were both doing a lot of SAS programming work for a bank and this was in the era of IBM 3179G graphics terminals. SAS had just pushed out a new procedure called g3d for creating three dimensional plots. We were both kind of blown away by the sample program that came with SAS/Graph called the "Cowboy Hat." Well, long story short, David and I both wanted to find a way to create that kind of plot with our bank data, even if it killed us.
Over the course of three weeks (mostly in our spare time, obviously), we tried numerous variations of data that we had in our DB but the plots that came out of g3d never looked anywhere as good as the sample program. We would submit programs and wait for 10 minutes to slowly see our graphics terminal display the top part of the plot, wait another five seconds, and then watch the bottom part of the plot appear. We were always disappointed at what we had created.
One day, we learned that there was a project going on inside the bank to optimize the branch system and all the customer accounts had been geocoded with lat/long coordinates. Both our eyes lit up at the same time because we knew we finally had some data we could use to make a "cool" plot. As we investigated the file, things just kept getting better. There were additional coordinate pairs that specified the nearest "major intersection" and the coordinates of the centroid for the census block group that the account belonged.
We ended up using deposit balances for our Z axis, and the lat/long coordinates for our X and Y pair. After tweaking the code, we got this amazing plot to come out. It was a plot showing the strength of deposit balances over a specified area (Wayne, Oakland and Macomb counties) and the plot demonstrated all the characteristics of the Central Business District and Central Place Theory that is discussed in modern geography. We were both tickled to death. In retrospect, between the mainframe charge backs and our time that we billed, that plot could vie for the most expensive plot made to that date. But we didn’t care! It looked amazingly cool.
So to answer your question David, "Yes, R can do the Cowboy Hat." For reference, here’s a link to the SAS/Graph version.
Here’s the WPS and R code to do the same plot.
*–> Cowboy hat;
do x=-5 to 5 by .25;
do y=-5 to 5 by .25;
*–> Perspective plots;
surface <- interp(x, y, z)
persp(surface, axes="TRUE", theta=110, phi=15,
title("Cowboy Hat with R",font.main=1)
And the R version of the Cowboy Hat.
About the author: Phil Rack is President of MineQuest, LLC. and has been a SAS language developer for more than 25 years. MineQuest provides WPS and SAS consulting and contract programming services and a reseller of WPS in North America.