更新时间:2023-12-01 12:11:04
We can use count
and then use ggplot
to plot the frequency. Here, we are plotting it with geom_bar
(as it is not clear from the OP's post)
library(dplyr)
library(ggplot2)
df %>%
count(square_id, Smart_Nsmart) %>%
ggplot(., aes(x= square_id, y = n, fill = Smart_Nsmart)) +
geom_bar(stat = 'identity')