Вы также можете попробовать это:
require(data.table)
library(dplyr)
library(ggplot2)
fake_data <- data.table(name = c('John', 'Peter', 'Alan', 'James', 'Jack', 'Elena', 'Maria'),
year = c(2018, 2018, 2018, 2017, 2016, 2017, 2018))
fake_data %>%
group_by(year) %>%
summarize(numb_people = length(unique(name)),
number_people_freq = length(unique(name))/ 5) %>%
as.data.table() %>%
ggplot(., aes(year)) +
geom_bar(aes(y = number_people_freq), stat = 'identity') +
labs(title = "...", x = "year", y = "frequency")]