tidytuesday 2020 Semana 03

Passwords

Autor

Lucas Carmo

Publicado

2020 - 01 - 14

library(tidyverse)
── Attaching core tidyverse packages ──────────────────────── tidyverse 2.0.0 ──
✔ dplyr     1.1.4     ✔ readr     2.1.5
✔ forcats   1.0.0     ✔ stringr   1.5.1
✔ ggplot2   3.5.0     ✔ tibble    3.2.1
✔ lubridate 1.9.3     ✔ tidyr     1.3.1
✔ purrr     1.0.2     
── Conflicts ────────────────────────────────────────── tidyverse_conflicts() ──
✖ dplyr::filter() masks stats::filter()
✖ dplyr::lag()    masks stats::lag()
ℹ Use the conflicted package (<http://conflicted.r-lib.org/>) to force all conflicts to become errors
library(stringr)
library(janitor)

Attaching package: 'janitor'

The following objects are masked from 'package:stats':

    chisq.test, fisher.test

Data

passwords <-
    readr::read_csv(
        "https://raw.githubusercontent.com/rfordatascience/tidytuesday/master/data/2020/2020-01-14/passwords.csv"
    ) %>%
    remove_empty("rows")
Rows: 507 Columns: 9
── Column specification ────────────────────────────────────────────────────────
Delimiter: ","
chr (3): password, category, time_unit
dbl (6): rank, value, offline_crack_sec, rank_alt, strength, font_size

ℹ Use `spec()` to retrieve the full column specification for this data.
ℹ Specify the column types or set `show_col_types = FALSE` to quiet this message.

Wrangle

pass <- passwords %>%
    mutate(char_category = case_when(
        str_detect(.$password, pattern = "^[a-z]+$") ~ "Only Lowercase",
        str_detect(.$password, pattern = "^[0-9]+$") ~ "Only Numeric",
        str_detect(.$password, pattern = "[:alnum:]") ~ "Alphanumeric",
        str_detect(.$password, pattern = "[:punct:]") ~ "With Punctuation",
    )) %>%
    select(password, char_category, strength)

Plot

ggplot(pass, aes(
    x = char_category,
    y = strength,
    color = char_category
)) +
    geom_violin(fill = NA) +
    geom_jitter(width = 0.1, alpha = 0.3, size = 0.8) +
    theme(
        panel.background = element_rect(fill = "#132124", color = NULL),
        panel.grid = element_blank(),
        panel.border = element_blank(),
        legend.position = "none",
        text = element_text(family = "Fira Code", color = "white"),
        axis.text = element_text(color = "white"),
        plot.title = element_text(lineheight = 1),
        plot.background = element_rect(fill = "#132125", color = NULL),
        plot.caption = element_text(hjust = 0)
    ) +
    scale_color_manual(values = c("#d33682", "#268bd2", "#2aa198")) +
    coord_flip() +
    labs(
        y = "\nStrength",
        x = "",
        title = "Top 500 passwords do not \nfollow security recommendations",
        caption = "\nData: Information is beautiful | Viz: @carmo_lcl"
    ) +
    annotate(
        geom = "text", x = 2, y = 20,
        label = 
        "Passwords containing only letters \n
        or words are not as strong and more \n
        frequent than passwords containing \n
        a combination of these elements",
        family = "Courier", color = "white", hjust = "left", size = 3
    )
Warning in grid.Call(C_stringMetric, as.graphicsAnnot(x$label)): font family
not found in Windows font database

Warning in grid.Call(C_stringMetric, as.graphicsAnnot(x$label)): font family
not found in Windows font database

Warning in grid.Call(C_stringMetric, as.graphicsAnnot(x$label)): font family
not found in Windows font database
Warning in grid.Call(C_textBounds, as.graphicsAnnot(x$label), x$x, x$y, : font
family not found in Windows font database

Warning in grid.Call(C_textBounds, as.graphicsAnnot(x$label), x$x, x$y, : font
family not found in Windows font database

Warning in grid.Call(C_textBounds, as.graphicsAnnot(x$label), x$x, x$y, : font
family not found in Windows font database

Warning in grid.Call(C_textBounds, as.graphicsAnnot(x$label), x$x, x$y, : font
family not found in Windows font database
Warning in grid.Call.graphics(C_text, as.graphicsAnnot(x$label), x$x, x$y, :
font family not found in Windows font database

Warning in grid.Call.graphics(C_text, as.graphicsAnnot(x$label), x$x, x$y, :
font family not found in Windows font database

Warning in grid.Call.graphics(C_text, as.graphicsAnnot(x$label), x$x, x$y, :
font family not found in Windows font database

Warning in grid.Call.graphics(C_text, as.graphicsAnnot(x$label), x$x, x$y, :
font family not found in Windows font database

Warning in grid.Call.graphics(C_text, as.graphicsAnnot(x$label), x$x, x$y, :
font family not found in Windows font database