library(RMySQL)
library(tidyverse)

con <- dbConnect(RMySQL::MySQL(), 
                 dbname = "sakila", 
                 port=3306,
                 user='root',
                 password='senha123#@!')

Lista de tabelas

dbListTables(con)
##  [1] "actor"                      "actor_info"                
##  [3] "address"                    "category"                  
##  [5] "city"                       "country"                   
##  [7] "customer"                   "customer_list"             
##  [9] "film"                       "film_actor"                
## [11] "film_category"              "film_list"                 
## [13] "film_text"                  "inventory"                 
## [15] "language"                   "nicer_but_slower_film_list"
## [17] "payment"                    "rental"                    
## [19] "sales_by_film_category"     "sales_by_store"            
## [21] "staff"                      "staff_list"                
## [23] "store"

Criando df com tabela selecionada

df <- tbl(con, "film")
df
## # Source:   table<film> [?? x 13]
## # Database: mysql 8.0.29 [@localhost:/sakila]
##    film_id title           description release_year language_id original_langua~
##      <dbl> <chr>           <chr>       <chr>              <dbl>            <dbl>
##  1       1 ACADEMY DINOSA~ A Epic Dra~ 2006                   1               NA
##  2       2 ACE GOLDFINGER  A Astoundi~ 2006                   1               NA
##  3       3 ADAPTATION HOL~ A Astoundi~ 2006                   1               NA
##  4       4 AFFAIR PREJUDI~ A Fanciful~ 2006                   1               NA
##  5       5 AFRICAN EGG     A Fast-Pac~ 2006                   1               NA
##  6       6 AGENT TRUMAN    A Intrepid~ 2006                   1               NA
##  7       7 AIRPLANE SIERRA A Touching~ 2006                   1               NA
##  8       8 AIRPORT POLLOCK A Epic Tal~ 2006                   1               NA
##  9       9 ALABAMA DEVIL   A Thoughtf~ 2006                   1               NA
## 10      10 ALADDIN CALEND~ A Action-P~ 2006                   1               NA
## # ... with more rows, and 7 more variables: rental_duration <dbl>,
## #   rental_rate <dbl>, length <dbl>, replacement_cost <dbl>, rating <chr>,
## #   special_features <chr>, last_update <chr>

Agrupando df por rating e contando entradas

contagem <- df %>% group_by(rating) %>% count() %>% arrange(desc(n))
contagem 
## # Source:     SQL [5 x 2]
## # Database:   mysql 8.0.29 [@localhost:/sakila]
## # Ordered by: desc(n)
##   rating     n
##   <chr>  <dbl>
## 1 PG-13    223
## 2 NC-17    210
## 3 R        195
## 4 PG       194
## 5 G        178

Retornando a QUERY utilizada

contagem %>% show_query()
## <SQL>
## SELECT `rating`, COUNT(*) AS `n`
## FROM `film`
## GROUP BY `rating`
## ORDER BY `n` DESC