This code
library(ggplot2)
library(dplyr)
DF <- data.frame(movieId = sample(1:100,size = 500, replace = TRUE),
rating = sample(1:5, size = 500, replace = TRUE))
DF %>% group_by(movieId) %>%
summarize(n = n()) %>%
ggplot(aes(n)) + geom_histogram(fill = "rosybrown2")
should run very quickly. The data frame has 500 rows and the plotted data has 100 rows. Try breaking it up into three steps, run each step individually, and find which step is taking so long.
library(ggplot2)
library(dplyr)
DF <- data.frame(movieId = sample(1:100,size = 500, replace = TRUE),
rating = sample(1:5, size = 500, replace = TRUE))
DF2 <- DF %>% group_by(movieId) %>%
summarize(n = n())
ggplot(DF2, aes(n)) + geom_histogram(fill = "rosybrown2")