Evan Martin (evan) wrote in evan_tech,
Evan Martin

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.

  • blog moved

    As described elsewhere, I've quit LiveJournal. If you're interested in my continuing posts, you should look at one of these (each contains feed…

  • dremel

    They published a paper on Dremel, my favorite previously-unpublished tool from the Google toolchest. Greg Linden discusses it: "[...] it is capable…

  • treemaps

    I finally wrote up my recent adventures in treemapping, complete with nifty clickable visualizations.

  • Post a new comment


    default userpic
    When you submit the form an invisible reCAPTCHA check will be performed.
    You must follow the Privacy Policy and Google Terms of use.