I would like to produce a stacked barplot of my dataframe (df) using tidyr but cannot quite figure out how to transform my dataframe appropriately. I think the answer is to use the melt function in the Reshape2 package but I cannot figure it out. Reproducible example below.
{time <- c("Day", "Day", "Night", "Night", "All", "All")
a <- c(70, 60, 35, 40, 50, 30)
b <- c(30, 40, 65, 60, 50, 70)
df <- data.frame(time, a, b)}
Variables A and B represent time spent in two different behavioral states (all equal to 100%) while Time represents a general qualitative description of when data were collected (day, night, or all times). I would like to transform the data to combine variables A and B into a single column so I can produce a stacked barplot with three bars (day, night, all) of the percent time spent in each behavioral state.