[R] Plot trajectories using ggplot?
Mike Smith
mike at hsm.org.uk
Sat May 14 10:18:07 CEST 2016
Hi
Ive got stuck using the code below to try to plot trajectories - columns are data recorded at time points, rows are cases. Ive used melt to turn the data long allowing me to group by time point and then plot using geom_point but I now need to join the points based upon the correct case (i.e. the first row in the original dataset). geo_segment allows me to specify start-end but I need to do this over multiple time periods....
Any help much appreciated
thanks
mike
library(reshape2)
library(ggplot2)
library(ggthemes)
library(cowplot)
#Read raw data
df = read.table("http://www.lecturematerials.co.uk/data/sample.csv", header=TRUE, sep=",", dec=".", na.strings=c("NA"))
names(df)<-c("1","2","3","4")
#Turn data from wide to long
ds<-melt(df)
ggplot(ds, aes(x = variable, y = value)) +
geom_point (shape=19, size=5, fill="black")
---
Mike Smith
More information about the R-help
mailing list