Tag: r

R and colour palettes part 2 - set your primary

A few posts ago, I got very invested in how to build a nice colour palette in R. I went through how to build your own palette, select colours depending on the number of series you needed to show, and how to wrap it all up in some handy shortcut functions, so you could feel like a real pro as you bring your own colour palette in to help with whatever plot you need to build.

What could be better than a whole article devoted to colour palettes in R? Did you guess, doubling down with a follow-up article about niche aspects of colour palettes? If so, you’d be correct.

Making a colour palette pseudo-package in R

Late last year, I got sick. Stuck at home, I had nothing to do, and I decided to amuse myself by making a colour palette package in the R programming language. The goal of this package was to make it as easy as possible to use a pre-defined colour palette in data visualisation.

While I tend not to use this in its package form in my day-to-day, a lot of the functions I go into in this article get copied-and-pasted from project to project. One of these days I’ll have enough time to package them up properly and get them into our local library, and then I’ll never have to type a hex code in ever again.

The case of the missing zero index

R is 1-indexed. Some people probably get unreasonable riled up about this.

arr <- c("first entry", "second entry", "third entry")
arr[1] # => [1] "first entry"

But what happens if you try to use 0 as an index?

Infix operators I have known and loved

For the last month or so, I’ve been learning the R programming language. It’s been super-interesting, and quite the change from my usual stomping grounds of high-level OO languages like ruby or python.

I’m now past the point of complete beginner, and getting my teeth into some of the more advanced stuff.1 One thing I’ve already had a bunch of fun with, however, is R’s infix operator syntax.