I have a data frame whereby the first column contains a list of numeric ID's which I have factored. The second column contains a numeric rating (between 1-10) for each ID, each ID may appear multiple times in the data frame as it may have multiple ratings. I want to iterate over the ID's and create a histogram (or similar) showing the distribution of ratings per ID.Then print each plot to the same pdf file.
My code so far:
pdf("Dist_Ratings_per_Movie_plots.pdf")
for (i in levels(movieRatings$MovieID)){
var <- movieRatings$i[movieRatings$Rating]
qplot(var, data = movieRatings, geom = "bar")
}
dev.off()
Note: This produces a pdf file with nothing written to it.
Example of movieRatings:
MovieID Rating
1234 6
1235 8
1234 7
1236 9
Any help is much appreciated