Created
December 17, 2010 17:26
-
-
Save trhaynes/745316 to your computer and use it in GitHub Desktop.
Plots a week's worth of browsing data by age group
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
pdf(file="testing.pdf", width=11, height=4.5, family="Helvetica") | |
# read in table and remove rows with NAs | |
agedata <- na.omit(read.table("sessions_by_age_10min.txt", sep="|", header=T)) | |
color <- c("#0000FF", "#FF1D25", "#009103", "#F7941E", "#00A8E2", "#FFA4D6") | |
# (probably an easier way to do this) | |
agedata$color[agedata$q6==0] <- color[1] | |
agedata$color[agedata$q6==1] <- color[2] | |
agedata$color[agedata$q6==2] <- color[3] | |
agedata$color[agedata$q6==3] <- color[4] | |
agedata$color[agedata$q6==4] <- color[5] | |
agedata$color[agedata$q6==5] <- color[6] | |
ages <- c("<18", "18-25", "26-35", "36-45", "46-55", "55+") | |
survey = read.table("survey.csv", sep=",", header=T) | |
plot(agedata$stimestamp, agedata$total, type="n", ylim=c(0, .4), ylab="", xaxt="n") # for scales | |
# add a series for each age group | |
for(i in unique(agedata$q6)) { | |
t = agedata[agedata$q6==i,] | |
x = length(which(survey$q6==i)) | |
print(x) | |
t$freq <- t$total/x | |
# t$freq <- t$total | |
# points(t$stimestamp, t$freq, col=t$color, type="p", pch=19, cex=.12) | |
lines(lowess(t$stimestamp, t$freq, f=.04), lwd=2, col=t$color) | |
} | |
axis(1, at=c(1288756800, 1289361600)) # x axis | |
legend("topleft", legend=ages, lwd=1.5, col=color, cex=.7) | |
dev.off() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment