# Articles by nzcoops

### Shading between two lines – ggplot

June 1, 2014 |

First one to say geom_ribbon loses. I was plotting some data for a colleague, had two lines (repeated experiment) per person (time on the x axis) facetted by id, I thought it’d be nice to shade the area between the … Continue reading → [Read more...]

### Finding the midpoint when creating intervals

May 23, 2014 |

Nothing ground breaking here. I was doing some work dividing data into deciles and then creating some plots. I couldn’t find an function to calculate this from cut, and I use cut quite a bit. So here we are. midpoints … Continue reading → [Read more...]

### ggplot + powerpoint = wall + head … solution?

September 2, 2013 |

Confession, by ‘solution?’ I literally mean I’m asking for your thoughts on a solution. Like it or lump it I do a lot of graphs for presentations, largely in powerpoint. That’s the way my colleagues/industry work(s) and it’s not about … Continue reading → [Read more...]

### Updated age calculation function

June 12, 2013 |

I had previously posted a function for calculating age with two dates. This was for the whole number ‘age’ where we are assuming you don’t want someone to be recorded as ’18′ until their 18th birthday (so more than just … Continue reading → [Read more...]

### ggplot graphs in publications?

November 6, 2012 |

The grey background and/or default choice of colours for groups makes a ggplot graph stand out to any R user when seen in a presentation. But ggplot graphs get all ninja when it comes to publications, either that or not … Continue reading → [Read more...]

### Forest plots in R (ggplot) with side table

November 6, 2012 |

A friend asked me to help with a forest plot recently. After chatting about what she wanted the end result to look like, this is what I came up with. grid.arrange(data_table, p, ncol=2) ## Warning: Removed 1 rows containing missing … Continue reading → [Read more...]

### Popularity indicator, with images (NFL)

September 23, 2012 |

It’s Friday night, there’s nothing good on TV, mmm conditions are perfect for shaggin about in R. So I’m an NFL fan, and (shameless plug) avid fan of this NFL podcast. They run their own pickem league which unless users … Continue reading → [Read more...]

### Simple plot with text boxes

September 21, 2012 |

Was doing a little presentation to our research group and had to explain the difficulties of ‘collapsing’ longitudinal data into a single measure when the Y var is quite variable. For the particular Y var of interest, it represents burden … Continue reading → [Read more...]

### (Manually) making letters with geom_path() – fun example

August 15, 2012 |

Disclaimer, maybe the title should be ‘lame example’. Nothing overly exciting here. Just posting cause it took a little faffing about and someone else might like the idea. At my work (research institute) we (the social club committee) were organising … Continue reading → [Read more...]

### Petrol prices adjusted for inflation

July 28, 2012 |

Petrol prices adjusted for inflation (Perth, Western Australia) The thought for this sprung to mind when I saw petrol drop below \$1.20 per litre the other day, and it made me think, I remember paying that when I got to … Continue reading → [Read more...]

### LME summary data – results table

May 21, 2012 |

UPDATE: Based on the comment from ‘linuxizer’, I’ve updated this to stay inline with the S3 classes, something I didn’t have my head around at the time, still don’t know it inside out. Brief post. One thing I do often … Continue reading → [Read more...]

### Kaplan-Meier Survival plot – with at risk table, by sub groups

May 4, 2012 |

This is a follow on from the previous post, with updated code. There was an argument ‘groups’ in the ggplot(…) line of the code that was working but is now no longer working with the updated version of R/ggplot2 (I … Continue reading → [Read more...]

### Kaplan-Meier Survival Plot – with at risk table

November 5, 2011 |

Credit for the bulk of this code is to Abhijit Dasgupta and the commenters on the original post here from earlier this year. I have made a few changes to the functionality of this which I think warrant sharing. A brief … Continue reading → [Read more...]

### Latent class mixed models – with graphics

October 2, 2011 |

Foreword Apologies that the output isn’t showing well as far as spacing and alignment is concerned. Am working on fixing that! Background Generally when we have a set of data, we have known groupings. Be that three different treatment groups, … Continue reading → [Read more...]

### Children height and blood pressure z-scores

September 20, 2011 |

Following on from some of my earlier posts, this is purely about, hopefully, saving some other people some time in putting this together. Height z-scores are required to then calculate the blood pressure z-scores. The CDC (Center for Disease Control … Continue reading → [Read more...]

### 2011 Perth City to Surf Stats

September 6, 2011 |

Like every year, August sees the thousands taking part in the Perth City to Surf, and with that comes the chance for some stats. Why? Curiosity more than anything, and to convince myself that my time in the 12km run … Continue reading → [Read more...]

### ICD code – search looping

July 15, 2011 |

Following on from my earlier post on creating a table of ICD codes in R, here is how I am currently counting these codes and storing the codes in a dataframe: Firstly create a dataframe to store the results in: hosp_count [Read more...]

### ICD codes – Analysing hospitilisations

July 14, 2011 |

A brief first post on what I hope will be a series of posts on analysing hospitilisation data, which is recorded using ICD codes (International Statistical Classification of Diseases and Related Health Problems) Initially here is an R file. This can be read in and will create a list, 218 long, ... [Read more...]

### gridExtra – Multiple plots from ggplot2

June 8, 2011 |

Thanks to this great post http://www.imachordata.com/?p=730 we can now put multiple plots on a display with ggplot2. This provides somewhat similar functionality to ‘par(mfrow=c(x,y))’ which would allow multiple plots with the base plot function. gridExtra doesn’t have quite the same level ... [Read more...]

### Generating unique random IDs

June 7, 2011 |

Recently I was asked to help create random IDs for someone. At first I thought, ‘Ah yup, 1:x (1,2,3, …,x), job done’. Then I thought that there had to be a R function/package to create better looking IDs, to which I didn’t find one, if there is, please let ... [Read more...]
1 2