Advertisement
Guest User

Untitled

a guest
Jan 6th, 2019
247
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
R 0.90 KB | None | 0 0
  1. # Load Libs
  2. library(ggplot2)
  3. library(ggTimeSeries) #fun for plotting calender-Heatmap
  4.  
  5. # Load Data
  6. dat = read.csv(file = 'philippjung_phone-nono.csv', header=TRUE)
  7.  
  8. # Data cleaning
  9. dat = dat[c(2,3)] #drop cols we don't need
  10. dat$DAYSTAMP = as.Date(dat$DAYSTAMP) #convert to Date
  11. 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
  12. colnames(fillDates) = ("DAYSTAMP")
  13. new = merge(dat, fillDates, by.x="DAYSTAMP", by.y="DAYSTAMP", all.x=TRUE, all.y=TRUE)
  14. new[is.na(new)] = 0 #replace NA with 0
  15. new$VALUE = as.logical(new$VALUE)
  16. clean_data = new[-1,] #drop first row
  17.  
  18. # Plotting
  19. ggplot_calendar_heatmap(clean_data, cDateColumnName = 'DAYSTAMP',
  20.                         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