I have data for the year that look like this:
datetime, key, value 1/1/15, 7k Steps, 1 1/1/15, Ate Poorly, 1 1/1/15, Audiobook, 1 1/1/15, Befriend, 1 1/1/15, Called Mom, 1 1/1/15, Code, 1 1/1/15, Create, 1 1/1/15, Critical, 1 1/1/15, Emailed Friend, 1 1/2/15, 10k Steps, 1 1/2/15, Ate Poorly, 1 1/2/15, Audiobook, 1 1/2/15, Befriend, 1 1/2/15, Called Mom, 1 1/2/15, Create, 1 1/2/15, Emailed Friend, 1 1/2/15, Exercise, 1 1/2/15, Friend Contact, 1 1/2/15, Great Day, 1 1/2/15, Write, 1 1/3/15, 7k Steps, 1 1/3/15, Ate Poorly, 1 1/3/15, Befriend, 1 1/3/15, Create, 1 1/3/15, Emailed Friend, 1 1/3/15, Friend Contact, 1 1/3/15, Great Day, 1 1/3/15, Happiness, 1 1/3/15, Health, 1 1/3/15, Videogame, 1 1/3/15, Walked With Michelle, 1 1/3/15, Write, 1 1/4/15, 7k Steps, 1 1/4/15, Ate Poorly, 1 1/4/15, Audiobook, 1 1/4/15, Great Day, 1 1/4/15, Happiness, 1 1/4/15, Health, 1 1/4/15, Impatient, 1 1/4/15, Love, 1 1/4/15, Movie With Michelle, 1
I want to create a chart that displays one row for each key with bars for each day, which has 1 for this key. Here is an example of the desired result:

What I painfully did with Python and Matplotlib.
I am looking for the best and easiest way to make such a graph in R with maybe ggplot2. I planned to use a bar graph in ggplot2 with a loop for each key. Here is an example of my code:
library(ggplot2) library(reshape) #library(ggtheme) # 2015 Lifedata Processing d <- read.csv("lifedata_2015.csv") d$datetime <- as.Date(d$datetime, "%m/%d/%Y") # Create a new dataframe with a subset of keys r <- d[d$key %in% c("Read", "Audiobook"), ] # Put 1s in all values. r$value <- 1 # Generate a data frame for each day with a value of 1 and a key of "alldates" mydates <- data.frame("datetime" = seq(as.Date("2015/1/1"), as.Date("2015/12/31"), "days"), "key" = "alldates", "value" = 1) # combine two data frames, one after the other n <- rbind(r, mydates) # Transform into a wide data frame based on datetime and key with mean as the value. c <- cast(n, datetime~key, mean) # Turn NaNs into 0 c[is.na(c)] = 0 for(name in c("Read", "Audiobook")){ plt <- c(plt, ggplot(data=c, aes_string(x="datetime", y=name)) + geom_bar(stat="Identity", width=1)) print(plot) } svg("~/Desktop/tagplot.svg") grid.arrange(plt, ncol = 1, main = "Read") dev.off()
This method does not seem to work.
What is the best way to build event data similar to the example above?