# Blog Archives

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

March 24, 2010
By

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 characteristi...

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

March 24, 2010
By

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 characteristi...

## ggplot2 (qplot) text size

February 22, 2010
By

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...

## Introduce your friends to R

February 12, 2010
By

## Introduce your friends to R

February 12, 2010
By

## Public opinion on health care reform

October 12, 2009
By

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 or opposing") points(as.Date(Dates),Favor,pch=16,col="#ADD8E6") lines(hc_fit.f1,col="blue",lwd=2)lines(hc_fit.o1,col="red",lwd=2)lines(hc_fit.f2,col="blue",lwd=2,lty=3)lines(hc_fit.o2,col="red",lwd=2,lty=3) abline(h=50,lwd=.5,lty=3,col="#555555")

## Public opinion on health care reform

October 12, 2009
By

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 or opposing") points(as.Date(Dates),Favor,pch=16,col="#ADD8E6") lines(hc_fit.f1,col="blue",lwd=2)lines(hc_fit.o1,col="red",lwd=2)lines(hc_fit.f2,col="blue",lwd=2,lty=3)lines(hc_fit.o2,col="red",lwd=2,lty=3) abline(h=50,lwd=.5,lty=3,col="#555555")

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

August 28, 2009
By

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,col="#FF9999",border=NA)rect(2010,-15,2014,6,col="#6699FF",border=NA)rect(2014,-15,2021,6,col="#CCCCCC",border=NA)abline(h=0,lwd=.5,lty=3,col="#555555")lines(fy,deficit.1,lwd=2.5)lines(fy,projected,lwd=2.5,lty=2)rect(1990,-11.5,2000,-9.5,col="#dddddd",border="#555555")text(1995,-10.5,"Source: CBO")graphics.off()

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

August 28, 2009
By

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,col="#FF9999",border=NA)rect(2010,-15,2014,6,col="#6699FF",border=NA)rect(2014,-15,2021,6,col="#CCCCCC",border=NA)abline(h=0,lwd=.5,lty=3,col="#555555")lines(fy,deficit.1,lwd=2.5)lines(fy,projected,lwd=2.5,lty=2)rect(1990,-11.5,2000,-9.5,col="#dddddd",border="#555555")text(1995,-10.5,"Source: CBO")graphics.off()

## Adding a legend to a plot

July 20, 2009
By

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="...