Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- # Load Libs
- library(ggplot2)
- library(ggTimeSeries) #fun for plotting calender-Heatmap
- # Load Data
- dat = read.csv(file = 'philippjung_phone-nono.csv', header=TRUE)
- # Data cleaning
- dat = dat[c(2,3)] #drop cols we don't need
- dat$DAYSTAMP = as.Date(dat$DAYSTAMP) #convert to Date
- fillDates = data.frame(seq.Date(from = as.Date('2018-11-15'), to = as.Date('2018-12-30'), by='day')) #create Date sequence to fill rows
- colnames(fillDates) = ("DAYSTAMP")
- new = merge(dat, fillDates, by.x="DAYSTAMP", by.y="DAYSTAMP", all.x=TRUE, all.y=TRUE)
- new[is.na(new)] = 0 #replace NA with 0
- new$VALUE = as.logical(new$VALUE)
- clean_data = new[-1,] #drop first row
- # Plotting
- ggplot_calendar_heatmap(clean_data, cDateColumnName = 'DAYSTAMP',
- cValueColumnName = 'VALUE') + labs(title='Morgendliche Smartphonenutzung', x='Monat', y='Wochentag') + guides(fill=guide_legend(title='Smartphone benutzt?'))
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement