I am fairly new to R and am attempting to plot data frames simultaneously using ggplot2.
I have two data frames.
One is called WorkSchedMonday and consist of 96 rows and 4 columns.
structure(c(9, 9, 9, 9, 18, 18, 36, 36, 36, 36, 64, 80, 96, 96,
112, 128, 168, 168, 296, 312, 14, 14, 14, 21, 21, 21, 21, 35,
49, 49, 12, 12, 6, 6, 0, 0, 0, 0, 6, 6), .Dim = c(10L, 4L), .Dimnames = list(
c("04:00", "04:15", "04:30", "04:45", "05:00", "05:15", "05:30",
"05:45", "06:00", "06:15"), c("WorkSchedAndIndivMondayAtHome",
"WorkSchedAndIndivMondayAtSingleWorkPlace", "WorkSchedAndIndivMondayAtVarietyOfPlaces",
"WorkSchedAndIndivMondayWorkingOnTheMove")))
The other is called WorkSchedTuesday and consist of 96 rows and 4 columns.
structure(c(0, 0, 0, 0, 9, 9, 27, 27, 36, 36, 64, 80, 96, 96,
112, 128, 168, 168, 296, 312, 14, 14, 14, 21, 21, 21, 21, 35,
49, 49, 12, 12, 6, 6, 0, 0, 0, 0, 6, 6), .Dim = c(10L, 4L), .Dimnames = list(
c("04:00", "04:15", "04:30", "04:45", "05:00", "05:15", "05:30",
"05:45", "06:00", "06:15"), c("WorkSchedAndIndivTuesdayAtHome",
"WorkSchedAndIndivTuesdayAtSingleWorkPlace", "WorkSchedAndIndivTuesdayAtVarietyOfPlaces",
"WorkSchedAndIndivTuesdayWorkingOnTheMove")))
Using the following code a plotted the 2 data frames.
WorkSchedWeek<-as.matrix(cbind(WorkSchedAndIndivMondayAtHome,WorkSchedAndIndivMondayAtSingleWorkPlace,WorkSchedAndIndivMondayAtVarietyOfPlaces, WorkSchedAndIndivMondayWorkingOnTheMove, WorkSchedAndIndivTuesdayAtHome,WorkSchedAndIndivTuesdayAtSingleWorkPlace,WorkSchedAndIndivTuesdayAtVarietyOfPlaces, WorkSchedAndIndivTuesdayWorkingOnTheMove))
####
melted_WorkSchedWeek<- melt(WorkSchedWeek)
plot<-ggplot(melted_WorkSchedWeek) + geom_col(aes(x = Var1,y = value,fill = Var2),position = "fill") + theme(legend.position="right", axis.text.x = element_text(angle = 90, hjust = 1))
plot + labs(x="Time", y="Probabilities", colour="Work schedules", fill="Work schedules")
However I would like to create the above plot using ggplot (or lattice) . On x axis is time (0400 till 0345 _ 24hours) per days (Monday and Tuesday), y axis probability distributions. The plot is filled with work schedules values. Can somebody help me? Thanks




dput(head(WorkSchedMonday, 10))anddput(head(WorkSchedTuesday, 10))into your question. - Jon Spring