Previous Entry Share Next Entry
09:18 pm, 1 Mar 05

hard drive prices

Noteworthy is the x axis label, and how it isn't numeric. I just figured that out today. The trick is you want R to compute the axis labels and spacing based on numbers but you want to assign the labels yourself.

You begin by adding axis=F to plot() to make it not draw a default axis. The axis() function takes a vector of labels, but it wants labels for each tick mark and not just the full labels of your data set. Thankfully, the axTicks() returns a vector of which data points correspond with which axis ticks, so you can reconstruct labels from those.

So after a cut'n'paste job from pricewatch:
> d = read.table('hd', col.names=c('price', 'size'))
> plot(d$size, d$price / d$size, type='l', main='Hard Drive Prices', axes=F, ylab='$/GB', xlab='Size')
> axis(2) # draw a normal Y axis
> axis(1, labels=paste(axTicks(1), "GB"))
> box()

Unfortunately, I don't know how to clean up the labelling on the Y axis -- many of those tick marks are just chartjunk. And the X axis labelling is a little offset to the right, and I ought to label the sweet spot (160GB) specially, and and and...

I'm still learning.