# Articles by Jim

### Using vectors to customize placement of tick marks and labels on a plot

March 24, 2010 |

OK, let's say you want to create a plot and you need an easy way to specify where along the scale your tick marks and labels land, as opposed to having R just decide itself. An easy way to do that is to create a vector and assign the axis ... [Read more...]

### ggplot2 (qplot) text size

February 22, 2010 |

I'm trying to learn qplot in ggplot2, and I'm having a difficult time adjusting text sizes. Well, difficult doesn't descibe it - I can't do it at all. The manual tells me I can use cex just like in plot, but it's not working... [Read more...]

### Introduce your friends to R

February 12, 2010 |

### Public opinion on health care reform

October 12, 2009 |

hc_appattach(hc_app) hc_fit.o1hc_fit.f1hc_fit.o2hc_fit.f2plot(as.Date(Dates),Oppose,main="Public opinion and health care reform",ylim=c(0,80),pch=16,xlim=c(as.Date("2009-01-01"),as.Date("2009-11-01")),cex.axis=.85, col="#E6ADD8",xlab="",ylab="Percentage approving ... [Read more...]

### Learning R 2009-08-28 13:11:00

August 28, 2009 |

fydeficit.1projectedpng("c:/data/deficit_color.png",height=480,width=480)plot(deficit.1~fy,ylim=c(-12,5),type="n",lwd=2,col="red",main="Federal budget deficit, 1990-2019",cex.lab=1.1,cex.axis=.75,xlab="Fiscal year",ylab="Deficit (% of GDP)")rect(1988,-15,1994,6,col="#FF9999",border=NA)rect(1994,-15,2002,6,col="#6699FF",border=NA)rect(2002,-15,2010,6,... [Read more...]

### Adding a legend to a plot

July 20, 2009 |

It's pretty easy!plot (c(1968,2010),c(0,10),type="n", # sets the x and y axes scales xlab="Year",ylab="Expenditures/GDP (%)") # adds titles to the axes lines(year,defense,col="red",lwd=2.5) # adds a line for defense expenditures lines(year,health,col="... [Read more...]

### Missing data, logistic regression, and a predicted values plot (or two)

July 15, 2009 |

miss attach miss result1 summary(result1) Call: glm(formula = a ~ b, family = binomial(logit)) Deviance Residuals: Min 1Q Median 3Q Max -1.8864 -1.2036 0.7397 0.9425 1.4385 Coefficients: Estimate Std. Error z value Pr(__|z|) (Intercept) -5.96130 1.40609 -4.240 2.24e-05 ***b 0.10950 0.02404 4.555 5.24e-06 ***---Signif. codes: 0 ‘***’ 0.001 ‘**’ 0.01 ‘*’ 0.05 ‘.’ 0.1 ‘ ’ 1(Dispersion parameter for binomial family taken to be 1) Null deviance: 279.97 on 203 ... [Read more...]

July 15, 2009 |

This plot:was created using the following R code:plot (q9e~q8, type = "n",xlim = c(1,13), ylim = c(1,13),cex.lab=1.25,cex.axis=0.75, col.lab = "#333333", xlab = "Obama job grade",ylab = "Congressional job grade", xaxt ="n", yaxt="n",main="Obama and Co... [Read more...]

### A recommended book

July 13, 2009 |

I've been getting a lot of help from this book:While written for S-Plus, nearly everything in it is applicable with R. [Read more...]

### Some detail on the last plot

July 13, 2009 |

First we plot approval (app) against date (daten). We also specify a few other things. ylim=c(40,80) specifies that the y axis extends from 40 to 80. xlim=c(-3,210) might seem odd, but we need extra space on the left. pch=16 plots dots, and col="gray" ... [Read more...]

### Obama approval

July 12, 2009 |

Working some more with time series data. Here we have a graph of Obama job approval numbers, with two LOWESS-fit lines added for trending: Figure1. President Obama job approval, Jan 2009 - present.There's actually some pretty fancy stuff going on there, as the following code shows.polls lfit1 lfit2 plot (... [Read more...]

### Return

July 6, 2009 |

I'm back from vacation, so I'll post something substantive later today. [Read more...]

### Time series data

June 28, 2009 |

gdp attach(gdp)as.Date(date)plot(gdp~date, data=gdp,pch=16,xlab="",ylab="GDP (2000 dollars)") [Read more...]

### Conservatism of Congressional delegation and %Bush vote

June 27, 2009 |

Busy day today, so I'll just post this:plot(bush04 ~ cons_hr, type = "n",xlab="Mean ACU rating",ylab="2004 Bush vote",xlim=c(0,100),ylim=c(0,100),cex.lab=1.25,cex.axis=0.75,col.axis = "#777777",col.lab = "#777777")text(y=bush04,x=cons_hr, labels=statei... [Read more...]

### Filtering cases

June 26, 2009 |

Something that's very important to be able to do in data analysis and visualization is to filter out cases. Let's say you want to do identical analyses of two different groups, or of one group and then a subset of it. R can do this a little differently; instead of ... [Read more...]

### A bit about linear models

June 26, 2009 |

Before we delve into slightly more advanced plotting commands I want to talk a little about linear models, specifically, linear regression. In R this is very, very simple. For instance, in our 'states' data frame, we might want to look at median household income as a predictor of state education ... [Read more...]

### Reading data, and a graph

June 25, 2009 |

Using Microsoft Excel I'm collecting aggregate data, by state, of various social, political, and economic indicators. I export them into a tab-delimited file called 'states.txt' (pretty clever, I know.) I've got data on education expenditures, firearm deaths per capita, median household income, etc. I'd like to do some analysis ... [Read more...]

### A start

June 24, 2009 |

I've decided that this summer I will finally break down and force myself to learn a little bit about using R. I currently use Stata, a very good program, but the idea of R is appealing since it's free under the GNU license. It has a large and active us... [Read more...]