I’m working through an R tutorial. Currently I’m making histograms. As the tutorial progresses it asks for changes to the already constructed histograms – add an xlab, add main etc etc.
That’s fine except each time I have to create the histogram from scratch.
How does one edit existing rather than write out all the code again? Would it be a matter of making the histogram an object and just editing it each time? I tried that. Lets say I start with this:
hearthist <- hist(outcome[,11])
I then want to add an xlabel. I tried this with no joy:
hearthist (xlab="30-Day Death Rate")
Whats the best practice here? Do I need to recreate a fresh histogram each time I want to add a parameter?
No; base graphics use a pen on paper idiom; once you make a mark that is it until you get a new piece of paper.
So, use to learn the appropriate tools. In this case an R-aware editor that you can write your R code and pipe it into a running R instance. I use ESS with Emacs, but the kool kids use RStudio. Give the latter a go.
Even standard, plain old R has a history mechanism which allows you to scroll back through your commands and re-run them from the command line.
Or learn to use the appropriate R tools.
title()allows you to addxlab,ylab,main, andsubto an existing plot.