If you don't do any programming in R you might think that it takes something
like this -- to produce something like this. Not so. Instead I can use lines of code
like this. I'll let you look at this for a few seconds. For those of you familiar
with the leaflet JavaScript library you might know where this is heading -- to make
a visualization like this -- a map of Starbucks in Atlanta from a geo coded
data file available for download at sakata's open data site you can click
and zoom this map and you could do the same thing with a starting point
anywhere in a broader zoom level now let's take a look at the code this first
line takes a CSV file and reads it into an R variable that I've called Starbucks
I'm using the built in R function read.csv if you haven't downloaded the
data yet you can download it directly from the URL The second line loads the
are a leaflet package this assumes I already installed the package on my
system if not I'd run one other line of code to install it. This line creates a
new blank leaflet map with basic map tiles. Line 4 tells the map to start off
at the lat and long I've entered which is Atlanta. I also set a zoom level to be
fairly local and this final line uses the add markers function to add markers.
Data for the markers comes from my Starbucks variable I created in line one.
We're also telling it which columns have lat and long info and that if you click a
marker you should get a pop-up with the locations name. Next up let's look at
Anthem stock prices before and after news of a big customer data breach -- so
say in the last six months here's your code three lines. That's it.
You don't have to even find and lo the data yourself just load the quant mod
package pull data for the stock symbol ANTM and generate the chart done. Quant
mod also pulls in data from the St. Louis Federal Reserve. I looked
their symbol for Atlanta-area unemployment so I can fetch that data
with one line of code -- this. This creates in our time series object with two
columns dates and data. I'll use a brand new R packets that hooks into the
digraphs javascript library. Now I can graph that data with one line of code.
It's a JavaScript graph so you can roll your cursor over to see the data points.
You can also click and drag to zoom in. If that ATLA TL a zero one three line
bugs you as a column name you can change it with this line of code. Next up we've
got a CSV file with school district score number of students and percent
students poor whore come from poor families question is there a correlation
between poverty rates and test results. Here I'll load the test data and the GG
viz library, create a basic plot object to look at percent poor by scores and
create two interactive sliders one for points eyes and one for opacity. The last
line adds a linear model - a line that best shows any trend or direction of all
the points. And in five lines of code I get an interactive scatter scatter plot
with two sliders where I can control point size and opacity. For correlation
coefficients among all the factors that's one line of code -- the NA.omit
removes rows with missing data and my data 3 : 6 says I just want columns 3
through 6 because those have the numbers. But a visualization is so much nicer.
Here's the code load the library, set the color palette, generate the correlation
plot - there you have it - five data visualizations in R and five lines of
code or less. I'm Sharon Machlis with Computerworld.