[R] Leaflet maps. Nudging co-incident markers

2018-01-19 Thread Gavin Rudge (Institute of Applied Health Research)
I have a dataset showing points, with a category for each point and its location. I simply want to display my points, in a way that users can toggle the points on and off by category. Where I have two objects in the same category I'd like to display them nudged to appear as two distinct, but v

[R] Alignment of a double plot where one has a switched axis

2016-02-05 Thread Gavin Rudge
Hi Rgonauts, I am plotting 3 variables from one data set on one plot. Two of them as a stacked bar and a ratio on a completely different scale, so I need to put one of the axes on the top of the plot for clarity. Whilst this is not good visualisation practice, there is a valid reason why, in

[R] Extracting xml data to data frames

2015-04-16 Thread Gavin Rudge
Hi Rgonauts, I am trying to parse some xml files of transport data using the TransExchange format (in this case bus routing information) and obtain some data.frames for onward processing for a GIS related task. Ideally I need them in .csv files. Each file (an example is attached) contains up t

[R] creating individual records from a frequency distribution

2014-10-22 Thread Gavin Rudge
I've got data frame containing a simple frequency distribution of numbers of people in three age groups by area. df1<-data.frame(area=c(1,2),group1=c(2,3),group2=c(1,5),group3=c(4,0)) df1 I want to get a data frame with one record per person (in my case 15 of them) which would look like this, w

[R] Running an encryption function on a column in a data.frame

2014-02-23 Thread Gavin Rudge
I am trying to encrypt postcodes (zipcodes) which, in my datasets, are strings with 8 characters, including spaces. By referring to other help files and other R resources I've built some (clumsy looking) code that turns a postcode into an output I'm happy with. See below. library("PKI") #make a

[R] generating a rank variable using date in a data.frame: overcoming a date origin error

2014-01-29 Thread Gavin Rudge
I've got a simple data.frame of a facotr variable called 'case' which indicates one subject and a date of an event ('obs'), each row representing an observation. One case can have many (or few) observations over time in the data set. I've created a crude data.frame by way of a clunky but reprod

[R] Create new records based on event dates in a data frame

2013-08-15 Thread Gavin Rudge
One of those simple tasks, but I can't get to first base with it. I've got a data set of observations of subjects over a 10 year period beginning on 1st April 2001 and ending on 31st March 2011. One of may variables is a score based on an intervention on a given date. Before the intervention t

[R] creating a quantile variable based on subsets of a dataframe

2013-08-06 Thread Gavin Rudge
#some sample data: library(Hmisc) set.seed(33) df<-data.frame(x=(sample(letters[1:10],1000,replace=TRUE)),y=rnorm(1000,mean=20,sd=15)) x is a category from a to J, say a geographical area, into which an observation y falls, y being a score. Now if I want to put my score into quantiles (quintile

[R] ggplot2: further query about back to back bar plots

2013-07-25 Thread Gavin Rudge
Further to my recent post on this topic and thanks to help received already (thanks BTW), I've got back-to-back plots working nicely to give me population pyramids, with some overlaid point data from a different time period, using the code below. #packages library(ggplot2) library(reshape2) lib

[R] Some problems with back to back bar plots in ggplot2

2013-07-17 Thread Gavin Rudge
Hi, I'm making a simple population pyramid using two back-to-back bar plots for 18 different age groups with totals for males and females. Yesterday I achieved a fairly serviceable plot using the following. library(ggplot2) library(reshape2) library(plyr) #make sample data df<-data.frame(ag=c(1:

[R] Obtaining predicted values from a zero-inflated poisson regression model

2013-07-05 Thread Gavin Rudge
I've got a data set of about 5,000 observations with a zero-inflated count response variable, two predictor variables and a variable which is effectively an area of opportunity, which I want to use as an offset term (all continuous). I want to explore the association between these variables, in

[R] animating plots over time with a slider

2013-05-15 Thread Gavin Rudge
I have a population of subjects each with a variable which has been captured at a baseline date. Then for many subjects (but not all) an intervention has occurred and the variable has changed at one or more time points after the baseline date. So my dataset consists of a subject ID (x), which

[R] predict.zeroinfl not found

2012-11-09 Thread Gavin Rudge
Hi Just a quick problem that I hope is simple to resolve. I'm doing some work with zero inflated poisson models using the pscl package. I can build models using zeroinfl and get outputs fom them with no problem, but when I try to use the predict.zeroinfl function, I get Error: could not find fu

[R] getting a Likert plot from a data frame

2012-05-22 Thread Gavin Rudge
I'm creating a stacked bar chart using the likert command in the HH package. My data are in a data frame, with two numeric variables and a categorical variable, I can't get likert to use the column containing the categorical variable as a my y axis label. Here is a quick example: library(HH)

[R] pyramid.plot in plotrix, axis labelling

2012-04-12 Thread Gavin Rudge
Hi, I've been looking at ways to make pyramid plots in R. I like the pyramid.plot method in plotrix as it seems the simplest to use and building them in ggplot looks a bit more code intensive than I'd like, being as I'm new to R. This package does pretty much what I need it to do, however I ca