For most of you this is an easy question so apologise for asking this.
I would like to melt my data.
My data structure
structure(list(PersonalCare = c(2, 2, 2, 2, 2, 2), Sleep = c(28,
60, 54, 58, 80, 78)), row.names = c("04:00", "04:10", "04:20",
"04:30", "04:40", "04:50"), class = "data.frame"
The data format is the following
Personalcare Sleep
04:00 2 28
04:10 2 60
04:20 2 54
04:30 2 58
04:40 2 80
04:50 2 78
05:00 2 110
05:10 2 156
05:20 1 172
05:30 1 192
05:40 1 214
After I melt my data using melted_PersonalcareSleep<- melt(PersonalcareSleep)
the format of my data changes to
1 04:00 Personalcare 2
2 04:10 Personalcare 2
3 04:20 Personalcare 2
4 04:30 Personalcare 2
5 04:40 Personalcare 2
6 04:50 Personalcare 2
7 05:00 Personalcare 2
8 05:10 Personalcare 2
9 05:20 Personalcare 1
10 05:30 Personalcare 1
11 05:40 Personalcare 1
...
145 04:00 Sleep 28
146 04:10 Sleep 60
147 04:20 Sleep 54
148 04:30 Sleep 58
149 04:40 Sleep 80
150 04:50 Sleep 78
....
After I plot my data with:
ggplot(melted_PersonalcareSleep, aes(x = Var1,y = value,group=Var2, color=Var2)) + geom_line(size=1) +labs(x="Time", y="Frequences", colour="Activties", fill="Activites" ) + theme(legend.position="right", axis.text.x = element_text(angle = 0, hjust = 0)) +annotate("rect", fill = "black", alpha = 0.3, xmin = c(97), xmax = c(121), ymin = -Inf, ymax = Inf)
As you can see on the image one activity is not shown correctly
How can I melt my data based on time (I don't want time to repeat itself).
Many thanks