Blog Archives

Stacked Bar Charts in R

January 10, 2013
By
Stacked Bar Charts in R

Reshape Wide to LongLet's use the Loblolly dataset from the datasets package. These data track the growth of some loblolly pine trees.> Loblolly   height age Seed1    4.51   3  30115  10.89   ...

Read more »

Mapping GPS Tracks in R

December 13, 2012
By
Mapping GPS Tracks in R

This is an explanation of how I used R to combine all my GPS cycling tracks from my Garmin Forerunner 305.Converting to CSVYou can convert pretty much any GPS data to .csv by using GPSBabel. For importing directly from my Garmin, I used the comman...

Read more »

Sorting Within Lattice Graphics in R

November 29, 2012
By
Sorting Within Lattice Graphics in R

DefaultBy default, lattice sorts the observations by the axis values, starting at the bottom left.For example,library(lattice)colors = c("#1B9E77", "#D95F02", "#7570B3")dotplot(rownames(mtcars) ~ mpg, data = mtcars, col = colors, pch = 1)produc...

Read more »

Palettes in R

October 25, 2012
By
Palettes in R

In its simplest form, a palette in R is simply a vector of colors. This vector can be include the hex triplet or R color names.The default palette can be seen through palette(): > palette("default") # you'll only need this line if you've previ...

Read more »

Random Name Generator in R

October 11, 2012
By

Just for the heck of it, let's recreate my Reality TV Show Name Generator in R. This isn't really the sort of thing you'd normally do in R, but we can try out a bunch of different functions this way: random integers/sampling, concatenation, sorting, an...

Read more »

Adding Measures of Central Tendency to Histograms in R

October 4, 2012
By
Adding Measures of Central Tendency to Histograms in R

Building on the basic histogram with a density plot, we can add measures of central tendency (in this case, mean and median) and a legend.Like last time, we'll use the beaver data from the datasets package.hist(beaver1$temp, # histogram col =...

Read more »

Histogram + Density Plot Combo in R

September 27, 2012
By
Histogram + Density Plot Combo in R

Plotting a histogram using hist from the graphics package is pretty straightforward, but what if you want to view the density plot on top of the histogram? This combination of graphics can help us compare the distributions of groups.Let's use...

Read more »

Descriptive Statistics of Groups in R

September 20, 2012
By

The sleep data set—provided by the datasets package—shows the effects of two different drugs on ten patients. Extra is the increase in hours of sleep; group is the drug given, 1 or 2; and ID is the patient ID, 1 to 10.I'll be using this data set to show how to perform descriptive statistics of groups within...

Read more »

Word Clouds in R

September 13, 2012
By
Word Clouds in R

Thanks to the wordcloud package, it's super easy to make a word cloud or tag cloud in R.In this case, the words have been counted already. If you are starting with plain text, you can use the text mining package tm to obtain the counts. Other blog...

Read more »