Fixing CSV Errors

summary(ds)
##    2 Mello          Sounds Of Tokyo-To Future Don't Stop Now! (Interlude)
##  Length:17922       Length:17922              Length:17922               
##  Class :character   Class :character          Class :character           
##  Mode  :character   Mode  :character          Mode  :character           
##      ...4          
##  Length:17922      
##  Class :character  
##  Mode  :character
names(ds)
## [1] "2 Mello"                     "Sounds Of Tokyo-To Future"  
## [3] "Don't Stop Now! (Interlude)" "...4"
names(ds)[1] <- 'Artist'
names(ds)[2] <- 'Album'
names(ds)[3] <- 'Track'
names(ds)[4] <- 'Date and Time' 
summary(ds)
##     Artist             Album              Track           Date and Time     
##  Length:17922       Length:17922       Length:17922       Length:17922      
##  Class :character   Class :character   Class :character   Class :character  
##  Mode  :character   Mode  :character   Mode  :character   Mode  :character

Reformatting and mutating DS

ds$'Date and Time' = as.POSIXlt(ds$`Date and Time`, format="%d %B %Y %H:%M")
ds$date = as.Date(ds$`Date and Time`)
ds$Artist = as.factor(ds$Artist)
ds$Album = as.factor(ds$Album)
ds$Track = as.factor(ds$Track)

Making a Smaller DS

lastweek = dplyr::filter(ds, date > get("datevar"))

Making the Graph

piechart = dplyr::count(lastweek, lastweek$Artist)
piechart = piechart %>%
  rename("Artist" = "lastweek$Artist")
piechart$fraction = piechart$n / sum(piechart$n)
numchart = select(piechart, c('n'))
percentchart = select(filter(piechart, n<=5), c('fraction'))
piechart = piechart %>%
  add_row(Artist = "Other", n = sum(filter(numchart, n<=5)), fraction = sum(percentchart))
piechart = filter(piechart, n>=5)
piechartfinal = piechart
piechartfinal$ymax = cumsum(piechartfinal$fraction)
piechartfinal$ymin = c(0, head(piechartfinal$ymax, n=-1))
ggplot(piechartfinal, aes(ymax=ymax, ymin=ymin, xmax=4, xmin=3, fill=Artist)) +
     geom_rect() +
  scale_fill_brewer(palette=4) +
  coord_polar(theta="y") +
  xlim(c(2.75, 4)) +
  theme_void()