Archive for month: February, 2013

Plot ranges of data in R

21 Feb 2013
2013/02/21

How to control the limits of data values in R plots.

R has multiple graphics engines.  Here we will talk about the base graphics and the ggplot2 package.

We’ll create a bit of data to use in the examples:

one2ten <- 1:10

ggplot2 demands that you have a data frame:

ggdat <- data.frame(first=one2ten, second=one2ten)

Seriously exciting data, yes?

Default behavior

The default is — not surprisingly — to create limits so that the data comfortably fit. Read more →

R database interfaces

14 Feb 2013
2013/02/14

Several packages on CRAN provide (or relate to) interfaces between databases and R.  Here is a summary, mostly in the words of the package descriptions.  Remember that package names are case-sensitive.

The packages that talk about being DBI-compliant are referring to the DBI package (see below in “Other SQL”).

MySQL

dbConnect: Provides a graphical user interface to connect with databases that use MySQL.

RMySQL: The current version complies with the database interface definition as implemented in the package DBI 0.2-2.

TSMySQL: TSMySQL provides a MySQL interface for TSdbi. Comprehensive examples of all the TS* packages are provided in the vignette Guide.pdf with the TSdata package. Read more →

Bricks not monoliths

06 Feb 2013
2013/02/06

Chapter 32 of Tao Te Programming advises you to make bricks instead of monoliths.  Here is an example. The example is written with the syntax of R and is a data analysis, but the principle is valid no matter what language you use or what your task is.

Monolith

Here is an outline of a function  reminiscent of many novice attempts:

monolith <-
function (data, col="blue", pch=21) 
{
        # transform data
        # fit model to data
        # plot data, uses 'col' and 'pch'
        # get desired model results
        # return desired model results
}

Each of these comment lines may be many lines of code so that the whole function runs to pages. Read more →

© Copyright - Burns Statistics