Articles by aghaynes

Extract data from a PNG/TIFF

December 5, 2018 | aghaynes

Sometimes it’s useful to be able to extract data from a published figure. If the figure isn’t a vector based format (for which the numeric data is probably still in the file), it’s possible to digitize the image with R, click the points and extract it that ...
[Read more...]

lmer vs INLA for variance components

November 24, 2018 | aghaynes

Just for fun, I decided to compare the estimates from lmer and INLA for the variance components of an LMM (this isn’t really something that you would ordinarily do – comparing frequentist and bayesian approaches). The codes are below. A couple of plots are drawn, which show the distribution of ... [Read more...]

anytime – dates in R

November 8, 2018 | aghaynes

I just saw an announcement on R Bloggers about the anytime package. It looks to be a very handy package to convert dates in pretty much any format to Date or POSIX classes, without the need to define the format – it’s guessed by an underlying C++ library. It certainly ... [Read more...]

Estimating Pi

October 16, 2018 | aghaynes

I came across this post which gives a method to estimate Pi by using a circle, it’s circumscribed square and (lots of) random points within said square. Booth used Stata to estimate Pi, but here’s some R code to do the same thing… x [Read more...]

“Where to bird” geostats in R

August 15, 2018 | aghaynes

I just came across a nice little post on acquiring and visualizing geodata in R using the Max Planck Institute of Ornithology as an example. It’s by the rOpenSci guys. Some useful code in there by the look of it… ? Worth a look…
[Read more...]

Coloured output in the R console

July 12, 2018 | aghaynes

Just a little fun today… the R console isn’t the most interesting of things… text is typically either black or red (assuming default settings in RStudio). There’s a package though called crayon which allows one to change the style of text in terms of colour, background and some ...
[Read more...]

rOpenSci’s drake package

July 10, 2018 | aghaynes

If you don’t know rOpenSci, then I recommend checking them out. They write a lot of really good packages for R. A relatively new seems to be drake. I’ve not played with it yet, but it looks to be very useful at giving indications about which parts of ...
[Read more...]

Rough looking figures from R

July 4, 2018 | aghaynes

A recent blog post regarding data visualization had some barplots I liked the look of (aesthetically…for research purposes, they wouldn’t be suitable). They look as if they’ve be coloured in with a pencil, rather than having solid blocks of colour… I wondered whether it’s possible with ... [Read more...]

Beeswarms instead of histograms

June 28, 2018 | aghaynes

Histograms are good, density plots are also good. Violin and bean plots too. Recently I had someone ask for a plot where you could see each individual point along a continuum, give the points specific colours based on a second variable (similar to the figure), which deviates somewhat from the ...
[Read more...]

Merging spatial buffers in R

June 11, 2018 | aghaynes

I’m sure there’s a better way out there, but I struggled to find a way to dissolve polygons that touched/overlapped each other (the special case being buffers). For example,  using the osmdata package, we can download the polygons representing hospital buildings in Bern, Switzerland. library(osmdata) library(...
[Read more...]

Intersecting points and overlapping polygons

May 27, 2018 | aghaynes

I’ve been doing some spatial stuff of late and the next little step will involve intersecting points with possibly many overlapping polygons. The sp package has a function called over which returns the polygons that points intersects with. The catch though, is that it only returns the last (highest ... [Read more...]

Tips for great graphics

May 26, 2018 | aghaynes

R is a great program for generating top-notch graphics. But to get the best out of it, you need to put in a little more work. Here are a few tips for adapting your R graphics to make them look a little better. 1) Dont use the “File/Save as…/” menu. ...
[Read more...]

openrouteservice – geodata!

May 19, 2018 | aghaynes

The openrouteservice provides a new method to get geodata into R. It has an API (or a set of them) and an R package has been written to communicate with said API(s) and is available from GitHub. I’ve just been playing around with the examples on this page, ...
[Read more...]

grconvertX and grconvertY

May 15, 2018 | aghaynes

These two functions are unbelievably useful for positioning graphical elements (text, axes, labels, …) in R. They allow one to convert coordinates between various different formats. For instance, you can convert your user coordinate (say 5 where x ranges from 0 to 200) to normalized device coordinates (proportional distance across the device) and vice ...
[Read more...]

Flow charts in R

May 9, 2018 | aghaynes

Flow charts are an important part of a clinical trial report. Making them can be a pain though. One good way to do it seems to be with the grid and Gmisc packages in R. X and Y coordinates can be designated based on the center of the boxes in ...
[Read more...]

Count models in JAGS

May 17, 2017 | aghaynes

Looks like I’ll be diving into some Bayesian analyses using JAGS. This post is primarily intended as a collection of links to [potentially] useful information, but also includes a few initial thoughts (I might update it occasionally with new links). In terms of R packages, a very brief play ... [Read more...]

Emails from R

April 21, 2017 | aghaynes

There are a few packages for sending email directly from R, but I work in a place where none of these work due to strict network settings. To at least partially circumvent this, here’s some code to produce a PowerShell script to send email(s) via Outlook. The PowerShell ... [Read more...]

“Pretty” table columns

April 10, 2014 | aghaynes

Every now and then you might want to make a nice table to include directly in your documents without having to faff about with columns later in excel or word. Typical issues might be the specification of decimal places, converting a value and proportion/SE column into one to take ... [Read more...]

Import/Export data to and from xlsx files

April 5, 2013 | aghaynes

As Ive already written, getting data into R from your precious xlsx files is really handy. No need to clutter up your computer with txt or csv files. The previous post I wrote about the gdata package for importing data from xlsx files and was pointed to, among others, the ... [Read more...]
1 2

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)