dados = read_csv(
    here::here("data/participation-per-country.csv"),
    col_types = cols(
        .default = col_double(),
        site = col_character(),
        country = col_character(),
        geo = col_character(),
        four_regions = col_character(),
        eight_regions = col_character(),
        six_regions = col_character(),
        `World bank income group 2017` = col_character()
    )
) %>% 
    filter(usuarios > 200)
glimpse(dados)
## Rows: 121
## Columns: 21
## $ site                           <chr> "StackOverflow", "StackOverflow", "Stac…
## $ country                        <chr> "Argentina", "Australia", "Austria", "B…
## $ PDI                            <dbl> 49, 36, 11, 80, 65, 69, 70, 39, 63, 80,…
## $ IDV                            <dbl> 46, 90, 55, 20, 75, 38, 30, 80, 23, 20,…
## $ MAS                            <dbl> 56, 61, 79, 55, 54, 49, 40, 52, 28, 66,…
## $ UAI                            <dbl> 86, 51, 70, 60, 94, 76, 85, 48, 86, 30,…
## $ usuarios                       <dbl> 2798, 12313, 2518, 2558, 4275, 10717, 1…
## $ responderam_prop               <dbl> 0.5357398, 0.6133355, 0.6310564, 0.3928…
## $ perguntaram_prop               <dbl> 0.5210865, 0.5897832, 0.5933280, 0.4757…
## $ editaram_prop                  <dbl> 0.09256612, 0.14699911, 0.14932486, 0.0…
## $ comentaram_prop                <dbl> 0.25339528, 0.33395598, 0.35027800, 0.1…
## $ GNI                            <dbl> NA, 59570, 48160, 840, 44990, 11630, 68…
## $ Internet                       <dbl> 51.0, 79.5, 79.8, 5.0, 78.0, 45.0, 51.0…
## $ EPI                            <dbl> 59.02, NA, 63.21, NA, 61.21, 49.96, NA,…
## $ geo                            <chr> "arg", "aus", "aut", "bgd", "bel", "bra…
## $ four_regions                   <chr> "americas", "asia", "europe", "asia", "…
## $ eight_regions                  <chr> "america_south", "east_asia_pacific", "…
## $ six_regions                    <chr> "america", "east_asia_pacific", "europe…
## $ Latitude                       <dbl> -34.00000, -25.00000, 47.33333, 24.0000…
## $ Longitude                      <dbl> -64.00000, 135.00000, 13.33333, 90.0000…
## $ `World bank income group 2017` <chr> "Upper middle income", "High income", "…

Estamos interessados na relação entre quanto as pessoas de diferentes países comentam em questões dos outros. A proporção das pessoas do país que comentou nas questões de outros está medido na variável comentaram_prop.

Considerando essa variável, queremos examinar a relação entre ela e o quão hierárquicas são as relações em um país (PDI). Queremos também levar em conta o quanto as pessoas daquele país têm acesso à Internet (Internet) e qual o tamanho da base de dados que detectamos daquele país (usuarios).

Examinando essa relação

Faça uma visualização que usa os princípios de eficácia no projeto de visualizações para facilitar as comparações que você acha que são as mais importantes para entendermos esse contexto.

Resposta

No gráfico a seguir é apresentada a relação entre as pessoas de diferentes países que comentam em questões de outros e o quão hierárquicas são as relações do pais. Foi utilizado um gráfico de pontos para, primeiramente, analisar visualmente a relação entre as váriaveis. Visualmente a relação não se apresentou forte (próxima da linear), o que foi confirmado utilizando o coeficiente de correlação de Spearman.

Complementando a análise, foram adicionadas outras duas informações de interesse, a porcentagem de pessoas com acesso a internet do país e a quantidade de pessoas daquele país na base de dados. Utilizando os princípios de eficácia, foi utilizado o tamanho do ponto para representar a quantidade de pessoas na base de dados, dado que é uma variável diretamente relacionada a tamanho, e foi utilizada a cor do ponto, variando sua intensidade, para representar a proporção de acesso a Internet.

Como conclusão final, analisando a cor e tamanho dos pontos, percebemos que uma maior disponibilidade de acesso a internet implica em uma maior relação de pessoas comentando em assuntos exteriores, mesmo com a base de dados menor.

Os nomes de alguns países foram destacados no gráfico, nomeando os que possuem máximo e mínimo do comentaram_prop e o máximo e mínimo da porcentagem de acesso a internet.

grouped_data <- dados %>% group_by(country) %>%
    summarise(
        PDI = mean(PDI, na.rm = TRUE),
        comentaram_prop = mean(comentaram_prop, na.rm = TRUE),
        Internet = mean(Internet, na.rm = TRUE),
        usuarios = sum(usuarios, na.rm = TRUE),
        Latitude = mean(Latitude, na.rm = TRUE),
        Longitude = mean(Longitude, na.rm = TRUE),
        six_regions = six_regions[1]
    ) %>%
    arrange(desc(comentaram_prop))

max_point <- grouped_data %>% 
    filter(comentaram_prop == max(comentaram_prop))

min_point <- grouped_data %>%
    filter(comentaram_prop == min(comentaram_prop))

max_internet_point <- grouped_data %>%
    filter(Internet == max(Internet, na.rm = TRUE))

min_internet_point <- grouped_data %>%
    filter(Internet == min(Internet, na.rm = TRUE))

correlation <- cor(grouped_data$PDI, grouped_data$comentaram_prop, method = "spearman")

grouped_data %>%
    ggplot(aes(
        x = PDI,
        y = comentaram_prop,
        color = Internet,
        size = log10(usuarios)
    )) +
    scale_colour_gradient(low = "cyan", high = "darkcyan") +
    geom_point(alpha = .7) +
    geom_text(
        data = max_point,
        aes(label = country),
        vjust = 0, hjust = -0.7,
        color = "black", size=4
    ) +
    geom_text(
        data = min_point,
        aes(label = country),
        vjust = 0, hjust = -0.6,
        color = "black", size=4
    ) +
    geom_text(
        data = max_internet_point,
        aes(label = country),
        vjust = 0.3, hjust = 3.3,
        color = "black", size=4
    ) +
    geom_text(
        data = min_internet_point,
        aes(label = country),
        vjust = 3, hjust = 1.7,
        color = "black", size=4
    ) +
    geom_segment(
        data = max_point, color="black",
        aes(x = PDI, y = comentaram_prop, xend = PDI + 4, yend = comentaram_prop + .003),
        arrow = arrow(type="closed", length = unit(0.15, "cm")), , inherit.aes = FALSE
    ) +
    geom_segment(
        data = min_point, color="black",
        aes(x = PDI, y = comentaram_prop, xend = PDI + 4, yend = comentaram_prop + .003),
        arrow = arrow(type="closed", length = unit(0.15, "cm")), , inherit.aes = FALSE
    ) +
    geom_segment(
        data = max_internet_point, color="black",
        aes(x = PDI, y = comentaram_prop, xend = PDI - 10, yend = comentaram_prop),
        arrow = arrow(type="closed", length = unit(0.15, "cm")), , inherit.aes = FALSE
    ) +
    geom_segment(
        data = min_internet_point, color="black",
        aes(x = PDI, y = comentaram_prop, xend = PDI - 10, yend = comentaram_prop-0.02),
        arrow = arrow(type="closed", length = unit(0.15, "cm")), , inherit.aes = FALSE
    ) +
    labs(
        x = "Hierarquia das relações do pais (PDI)",
        y = "Pessoas que comentam questões exteriores (Proporção)",
        color = "Acesso a Internet",
        size = "Base de dados (log10)"
    ) +
    annotate("text", x = -Inf, y = -Inf, label = paste("Correlação (Spearman):", round(correlation, 2)), hjust = -0.1, vjust = -1) +
    ggtitle("comentaram_prop x PDI")

Outras formas de ver

Em seguida, faça 5 visualizações que usem as mesmas variáveis e também pontos, mas que sejam menos eficazes que a que você escolheu acima.

Visualização ruim 1

Utilizando o gradiente padrão da ferramenta (sem utilizar o scale_colour_gradient), maiores porcentagens de acesso a internet são mostradas com cores claras, indo contra ao princípio de eficácia, pois algo mais claro da a entender que seja menor que algo mais escuro:

grouped_data %>%
    ggplot(aes(
        x = PDI,
        y = comentaram_prop,
        color = Internet,
        size = log10(usuarios)
    )) +
    geom_point(alpha = .7) +
    geom_text(
        data = max_point,
        aes(label = country),
        vjust = 0, hjust = -0.7,
        color = "black", size=4
    ) +
    geom_text(
        data = min_point,
        aes(label = country),
        vjust = 0, hjust = -0.6,
        color = "black", size=4
    ) +
    geom_text(
        data = max_internet_point,
        aes(label = country),
        vjust = 0.3, hjust = 3.3,
        color = "black", size=4
    ) +
    geom_text(
        data = min_internet_point,
        aes(label = country),
        vjust = 3, hjust = 1.7,
        color = "black", size=4
    ) +
    geom_segment(
        data = max_point, color="black",
        aes(x = PDI, y = comentaram_prop, xend = PDI + 4, yend = comentaram_prop + .003),
        arrow = arrow(type="closed", length = unit(0.15, "cm")), , inherit.aes = FALSE
    ) +
    geom_segment(
        data = min_point, color="black",
        aes(x = PDI, y = comentaram_prop, xend = PDI + 4, yend = comentaram_prop + .003),
        arrow = arrow(type="closed", length = unit(0.15, "cm")), , inherit.aes = FALSE
    ) +
    geom_segment(
        data = max_internet_point, color="black",
        aes(x = PDI, y = comentaram_prop, xend = PDI - 10, yend = comentaram_prop),
        arrow = arrow(type="closed", length = unit(0.15, "cm")), , inherit.aes = FALSE
    ) +
    geom_segment(
        data = min_internet_point, color="black",
        aes(x = PDI, y = comentaram_prop, xend = PDI - 10, yend = comentaram_prop-0.02),
        arrow = arrow(type="closed", length = unit(0.15, "cm")), , inherit.aes = FALSE
    ) +
    labs(
        x = "Hierarquia das relações do pais (PDI)",
        y = "Pessoas que comentam questões exteriores (Proporção)",
        color = "Acesso a Internet",
        size = "Base de dados (log10)"
    ) +
    annotate("text", x = -Inf, y = -Inf, label = paste("Correlação (Spearman):", round(correlation, 2)), hjust = -0.1, vjust = -1) +
    ggtitle("comentaram_prop x PDI (Visualização ruim 1)")

Visualização ruim 2

Não aplicar o log10 nos usuários torna a distância entre os dados muito maiores, dificultando a comparação do banco de dados pelo tamanho:

grouped_data %>%
    ggplot(aes(
        x = PDI,
        y = comentaram_prop,
        color = Internet,
        size = usuarios
    )) +
    geom_point(alpha = .7) +
    geom_text(
        data = max_point,
        aes(label = country),
        vjust = 0, hjust = -0.7,
        color = "black", size=4
    ) +
    geom_text(
        data = min_point,
        aes(label = country),
        vjust = 0, hjust = -0.6,
        color = "black", size=4
    ) +
    geom_text(
        data = max_internet_point,
        aes(label = country),
        vjust = 0.3, hjust = 3.3,
        color = "black", size=4
    ) +
    geom_text(
        data = min_internet_point,
        aes(label = country),
        vjust = 3, hjust = 1.7,
        color = "black", size=4
    ) +
    geom_segment(
        data = max_point, color="black",
        aes(x = PDI, y = comentaram_prop, xend = PDI + 4, yend = comentaram_prop + .003),
        arrow = arrow(type="closed", length = unit(0.15, "cm")), , inherit.aes = FALSE
    ) +
    geom_segment(
        data = min_point, color="black",
        aes(x = PDI, y = comentaram_prop, xend = PDI + 4, yend = comentaram_prop + .003),
        arrow = arrow(type="closed", length = unit(0.15, "cm")), , inherit.aes = FALSE
    ) +
    geom_segment(
        data = max_internet_point, color="black",
        aes(x = PDI, y = comentaram_prop, xend = PDI - 10, yend = comentaram_prop),
        arrow = arrow(type="closed", length = unit(0.15, "cm")), , inherit.aes = FALSE
    ) +
    geom_segment(
        data = min_internet_point, color="black",
        aes(x = PDI, y = comentaram_prop, xend = PDI - 10, yend = comentaram_prop-0.02),
        arrow = arrow(type="closed", length = unit(0.15, "cm")), , inherit.aes = FALSE
    ) +
    labs(
        x = "Hierarquia das relações do pais (PDI)",
        y = "Pessoas que comentam questões exteriores (Proporção)",
        color = "Acesso a Internet",
        size = "Base de dados (sem log10)"
    ) +
    annotate("text", x = -Inf, y = -Inf, label = paste("Correlação (Spearman):", round(correlation, 2)), hjust = -0.1, vjust = -1) +
    ggtitle("comentaram_prop x PDI (Visualização ruim 2)")

Visualização ruim 3

Não ajustar o alpha dos pontos (transparência) torna difícil (ou até impossível) diferenciar pontos próximos, apresentando-se como formas distorcidas.

grouped_data %>%
    ggplot(aes(
        x = PDI,
        y = comentaram_prop,
        color = Internet,
        size = log10(usuarios)
    )) +
    geom_point(alpha = 1) +
    geom_text(
        data = max_point,
        aes(label = country),
        vjust = 0, hjust = -0.7,
        color = "black", size=4
    ) +
    geom_text(
        data = min_point,
        aes(label = country),
        vjust = 0, hjust = -0.6,
        color = "black", size=4
    ) +
    geom_text(
        data = max_internet_point,
        aes(label = country),
        vjust = 0.3, hjust = 3.3,
        color = "black", size=4
    ) +
    geom_text(
        data = min_internet_point,
        aes(label = country),
        vjust = 3, hjust = 1.7,
        color = "black", size=4
    ) +
    geom_segment(
        data = max_point, color="black",
        aes(x = PDI, y = comentaram_prop, xend = PDI + 4, yend = comentaram_prop + .003),
        arrow = arrow(type="closed", length = unit(0.15, "cm")), , inherit.aes = FALSE
    ) +
    geom_segment(
        data = min_point, color="black",
        aes(x = PDI, y = comentaram_prop, xend = PDI + 4, yend = comentaram_prop + .003),
        arrow = arrow(type="closed", length = unit(0.15, "cm")), , inherit.aes = FALSE
    ) +
    geom_segment(
        data = max_internet_point, color="black",
        aes(x = PDI, y = comentaram_prop, xend = PDI - 10, yend = comentaram_prop),
        arrow = arrow(type="closed", length = unit(0.15, "cm")), , inherit.aes = FALSE
    ) +
    geom_segment(
        data = min_internet_point, color="black",
        aes(x = PDI, y = comentaram_prop, xend = PDI - 10, yend = comentaram_prop-0.02),
        arrow = arrow(type="closed", length = unit(0.15, "cm")), , inherit.aes = FALSE
    ) +
    labs(
        x = "Hierarquia das relações do pais (PDI)",
        y = "Pessoas que comentam questões exteriores (Proporção)",
        color = "Acesso a Internet",
        size = "Base de dados (log10)"
    ) +
    annotate("text", x = -Inf, y = -Inf, label = paste("Correlação (Spearman):", round(correlation, 2)), hjust = -0.1, vjust = -1) +
    ggtitle("comentaram_prop x PDI (Visualização ruim 3)")

Visualização ruim 4

Uma escala desnecessariamente maior quando comparada ao limite dos dados esconde relações entre as variáveis. Aumentando a escala do eixo Y, que representa a variável comentaram_prop:

grouped_data %>%
    ggplot(aes(
        x = PDI,
        y = comentaram_prop,
        color = Internet,
        size = log10(usuarios)
    )) +
    geom_point(alpha = .7) +
    labs(
        x = "Hierarquia das relações do pais (PDI)",
        y = "Pessoas que comentam questões exteriores (Proporção)",
        color = "Acesso a Internet",
        size = "Base de dados (log10)"
    ) +
    annotate("text", x = -Inf, y = -Inf, label = paste("Correlação (Spearman):", round(correlation, 2)), hjust = -0.1, vjust = -1) +
    ggtitle("comentaram_prop x PDI (Visualização ruim 4)") +
    coord_cartesian(xlim = c(0, 110), ylim = c(-1, 1))  # Adjust x and y limits

Visualização ruim 5

Usar tamanhos de passo (do inglês step size) com tamanhos incomuns, como números impares, dificulta a leitura do gráfico para estimativa de pontos que não estejam alinhados com os passos.

grouped_data %>%
    ggplot(aes(
        x = PDI,
        y = comentaram_prop,
        color = Internet,
        size = log10(usuarios)
    )) +
    geom_point(alpha = .7) +
    labs(
        x = "Hierarquia das relações do pais (PDI)",
        y = "Pessoas que comentam questões exteriores (Proporção)",
        color = "Acesso a Internet",
        size = "Base de dados (log10)"
    ) +
    annotate("text", x = -Inf, y = -Inf, label = paste("Correlação (Spearman):", round(correlation, 2)), hjust = -0.1, vjust = -1) +
    ggtitle("comentaram_prop x PDI (Visualização ruim 5)") +
    scale_y_continuous(breaks = seq(0, 1, by = 0.07))

Bônus

Inclua o continente dos países (six_regions) na visualização.

Resposta

Como a informação de continente só possui 6 valores possíveis, podemos representa-la utilizando formatos diferentes para os pontos:

grouped_data %>%
    ggplot(aes(
        x = PDI,
        y = comentaram_prop,
        color = Internet,
        size = log10(usuarios),
        shape = six_regions
    )) +
    scale_colour_gradient(low = "cyan", high = "darkcyan") +
    geom_point(alpha = 5) +
    geom_text(
        data = max_point,
        aes(label = country),
        vjust = 0, hjust = -0.7,
        color = "black", size=4
    ) +
    geom_text(
        data = min_point,
        aes(label = country),
        vjust = 0, hjust = -0.6,
        color = "black", size=4
    ) +
    geom_text(
        data = max_internet_point,
        aes(label = country),
        vjust = 0.3, hjust = 3.3,
        color = "black", size=4
    ) +
    geom_text(
        data = min_internet_point,
        aes(label = country),
        vjust = 3, hjust = 1.7,
        color = "black", size=4
    ) +
    geom_segment(
        data = max_point, color="black",
        aes(x = PDI, y = comentaram_prop, xend = PDI + 4, yend = comentaram_prop + .003),
        arrow = arrow(type="closed", length = unit(0.15, "cm")), , inherit.aes = FALSE
    ) +
    geom_segment(
        data = min_point, color="black",
        aes(x = PDI, y = comentaram_prop, xend = PDI + 4, yend = comentaram_prop + .003),
        arrow = arrow(type="closed", length = unit(0.15, "cm")), , inherit.aes = FALSE
    ) +
    geom_segment(
        data = max_internet_point, color="black",
        aes(x = PDI, y = comentaram_prop, xend = PDI - 10, yend = comentaram_prop),
        arrow = arrow(type="closed", length = unit(0.15, "cm")), , inherit.aes = FALSE
    ) +
    geom_segment(
        data = min_internet_point, color="black",
        aes(x = PDI, y = comentaram_prop, xend = PDI - 10, yend = comentaram_prop-0.02),
        arrow = arrow(type="closed", length = unit(0.15, "cm")), , inherit.aes = FALSE
    ) +
    labs(
        x = "Hierarquia das relações do pais (PDI)",
        y = "Pessoas que comentam questões exteriores (Proporção)",
        color = "Acesso a Internet",
        size = "Base de dados (log10)"
    ) +
    annotate("text", x = -Inf, y = -Inf, label = paste("Correlação (Spearman):", round(correlation, 2)), hjust = -0.1, vjust = -1) +
    ggtitle("comentaram_prop x PDI") +
    scale_shape_manual(values = c(1, 2, 5, 7, 8, 11))