R Plotting tips

July 26, 2010

(This article was first published on EvolvingSpaces, and kindly contributed to R-bloggers)

Yes…I haven’t been updating the blog for a very long while…But I’m really busy with many things right know…. Our paper for the “Cultural Evolution in Spatially Structured Populations” have been accepted so we are currently working on that, and I have also stuffs for the PhD and a couple of papers I’m working on…busy busy busy…..
I’ve also started writing a couple of ABM using R, which sounds crazy at first (also at second, and third) but it has some nice things which I’ll write about extensively in a future post.
But for know, I just wanted to start a series of very small posts (mainly for archaeologists) of small tips, which are astonishing simple concepts which however takes a couple of hours of googling and forum foraging…
For instance, have you ever tried to plot a time series of BC or BP dates? Suppose you have a sequence of count per century as follows:


plotting this as a timeseries is very simple:


and then you realise that you want something meaningful on the x-axis and you write the follow


 perhaps, if you know a bit of R you’ll choose the more elegant nested function


In any case you’ll try to plot this as follow:


and you’ll find out that R ignored the ordering of the vector dates, and it even reversed your time-series.

My practical solution was to use negative values on the plot, and then delete the “-” with gimp or something (yes I should really be ashamed of myself).
Well for the small portion of people who had the same problem and here’s the solution


Basically you can tell to the plot function that the range of values for the x axis is from the greatest value (the oldest date in our case, thus the largest number) to the smallest value. R will simply then read the values of dates in the correct order and plot the TS in the way it should look like.

To leave a comment for the author, please follow the link and comment on their blog: EvolvingSpaces.

R-bloggers.com offers daily e-mail updates about R news and tutorials on topics such as: Data science, Big Data, R jobs, visualization (ggplot2, Boxplots, maps, animation), programming (RStudio, Sweave, LaTeX, SQL, Eclipse, git, hadoop, Web Scraping) statistics (regression, PCA, time series, trading) and more...

If you got this far, why not subscribe for updates from the site? Choose your flavor: e-mail, twitter, RSS, or facebook...

Comments are closed.

Search R-bloggers


Never miss an update!
Subscribe to R-bloggers to receive
e-mails with the latest R posts.
(You will not see this message again.)

Click here to close (This popup will not appear again)