yes

Dados wide x long

Exercícios

Diretrizes gerais:

  1. Instale o pacote reshape2

  2. Baixe o arquivo .Rmd e o .csvb e abra no RStudio.

Arquivo .Rmd

Arquivo .csv

  1. Siga as diretrizes da atividade.

  2. Rode o arquivo .Rmd por meio do ícone knitr

  3. Salve o .Rmd e submeta-o por meio do email .


Exercício 1.

Rode o código para gerar o histograma a seguir:

# library
library(tidyverse)
## -- Attaching packages --------------------------------------- tidyverse 1.3.1 --
## v ggplot2 3.3.5     v purrr   0.3.4
## v tibble  3.1.3     v dplyr   1.0.7
## v tidyr   1.1.3     v stringr 1.4.0
## v readr   2.0.1     v forcats 0.5.1
## -- Conflicts ------------------------------------------ tidyverse_conflicts() --
## x dplyr::filter() masks stats::filter()
## x dplyr::lag()    masks stats::lag()
library(reshape2)
## Warning: package 'reshape2' was built under R version 4.1.2
## 
## Attaching package: 'reshape2'
## The following object is masked from 'package:tidyr':
## 
##     smiths
# Build dataset with different distributions
data <- data.frame(
  type = c( rep("variable 1", 1000), rep("variable 2", 1000) ),
  value = c( rnorm(1000), rnorm(1000, mean=4) )
)

# Represent it
p <- data %>%
  ggplot( aes(x=value, fill=type)) +
    geom_histogram( color="#e9ecef", alpha=0.6, position = 'identity') +
    scale_fill_manual(values=c("#69b3a2", "#404080")) +
    theme_minimal() +
    labs(fill="")

p
## `stat_bin()` using `bins = 30`. Pick better value with `binwidth`.

Transformando dados de wide para long para representar dois dados iguais de recortes distintos no mesmo gráfico

dados_bh <- read_delim("/Users/Fernando/Downloads/dados_bh.csv",
delim = ";", escape_double = FALSE, trim_ws = TRUE)