R Project resource

Excellent website full of useful information on using R Project:


Topics include:
Getting data from the web
Data Manipulation
Data visualization

This is probably my favorite project on his site – not because it’s Star Wars, but because of the way the data is presented:


Unpivoting a Table

I have a pivot table with Routes going down and years going across, but I need to normalize it – have a column for the route and a column for the year and then a value for each route, column.

Bad Lands121288

Oracle and MS SQL databases have a function called UNPIVOT.

MySQL does not have a similar function yet, so you have to do a SELECT, UNION ALL type command.

In R Project, the function is called “Melt”

Doing this in R Project:

1. Install the reshape library if you don’t have it.
2. Program looks like so:

rte_vol_melted<-melt(rte_vol, id=c("Route")) rte_vol_melted

Line 1 runs the reshape library
Line 2 reads the data in
Line 3 "Melts" the data
Line 4 Shows the output

Intro to R-project

A second start at learning r-project.

Some very useful commands: Importing a csv file


To view the contents of the file that was just imported


Note that this isn’t a command – this is the name used from the command to import the file.

What is the current working directory


When the file was imported, you could pull up the data using the variable name, which would be yrseq in this case. The following command makes the same thing true for all the column names.


After putting in the above command, I can now type in the name of a field and get the data list. “tpd_base” for example.

List the names of the datasets loaded


List the names of variable in a given dataset

names (yrseq)

Starting Rserve Using Tableau with R-Project

References for the above:

R Tutorial Dr. Mark Gardner

mapproj in r

Making maps with r using mapproj.



map <- get_map(location=’North America’, zoom=6)



What each line does:

Line 1 loads the ggmap library.

Line 2 fetches the terrain map graphic from Google’s server at the specified zoom level – higher is closer in.  Zoom level 6 is about the size of Texas or California.  Zoom 15 is about the level of a neighborhood and is the max.  Going higher does zoom in further but there is no background.  The location value seems to be able to take any value that google maps would take.  The image is stored as “map”.

Line 3 displays the map.

Another example


a <- get_map(location=’ft worth, tx’,zoom=12)

Maps in R Project

Found some great information on how to make maps in R Project:

Maps in R: Introduction – Drawing the map of Europe

To install libraries, use the command “install.packages()”

This will bring up a list of packages to install, then you can select the package you need.  I was a little disappointed that I couldn’t put the package in the command line, like this: “install.packages(rworldmap)” and then it would download directly.  Maybe it actually can, but I wasn’t using the command correctly.