Atividade 6

1. Revisar os conceitos de análise bi-variada aprendidas na última aula.

2. Praticar a utilização de base de dados para extrair informações e conhecer melhor os dados.

3. Gerar gráficos para variáveis (no ggplot2).

Fase 1 - Carregando a base de dados

Nesta fase iremos carregar o banco de dados para ser realizada as análises.

options(digits=2)

library(readxl)
MOMA <- read_excel("C:/Users/Cristiane/Desktop/Atividade 06/arte_MOMA.xls")
## Warning in read_fun(path = enc2native(normalizePath(path)), sheet_i = sheet, :
## Expecting numeric in L1676 / R1676C12: got 'NA'
## Warning in read_fun(path = enc2native(normalizePath(path)), sheet_i = sheet, :
## Expecting numeric in L1861 / R1861C12: got 'NA'
## Warning in read_fun(path = enc2native(normalizePath(path)), sheet_i = sheet, :
## Expecting numeric in L1984 / R1984C12: got 'NA'
## Warning in read_fun(path = enc2native(normalizePath(path)), sheet_i = sheet, :
## Expecting numeric in L1986 / R1986C12: got 'NA'
## Warning in read_fun(path = enc2native(normalizePath(path)), sheet_i = sheet, :
## Expecting numeric in L1988 / R1988C12: got 'NA'
## Warning in read_fun(path = enc2native(normalizePath(path)), sheet_i = sheet, :
## Expecting numeric in L1989 / R1989C12: got 'NA'
## Warning in read_fun(path = enc2native(normalizePath(path)), sheet_i = sheet, :
## Expecting numeric in L1990 / R1990C12: got 'NA'
## Warning in read_fun(path = enc2native(normalizePath(path)), sheet_i = sheet, :
## Expecting numeric in L1991 / R1991C12: got 'NA'
## Warning in read_fun(path = enc2native(normalizePath(path)), sheet_i = sheet, :
## Expecting numeric in L2045 / R2045C12: got 'NA'
## Warning in read_fun(path = enc2native(normalizePath(path)), sheet_i = sheet, :
## Expecting numeric in H2220 / R2220C8: got 'NA'
## New names:
## * `` -> ...1

Fase 2 - Trabalhando com os dados:

MOMA$artist_gender<-ifelse(MOMA$n_female_artists==0,"MASCULINO","FEMININO")

MOMA$artist_birth_year <- as.factor(MOMA$artist_birth_year)

MOMA$artist_death_year <- as.factor(MOMA$artist_death_year)


library(dplyr)
## 
## Attaching package: 'dplyr'
## The following objects are masked from 'package:stats':
## 
##     filter, lag
## The following objects are masked from 'package:base':
## 
##     intersect, setdiff, setequal, union
library(ggplot2)
library(ggthemes)
library(tidyverse)
## -- Attaching packages --------------------------------------- tidyverse 1.3.0 --
## v tibble  3.0.6     v purrr   0.3.4
## v tidyr   1.1.2     v stringr 1.4.0
## v readr   1.4.0     v forcats 0.5.1
## -- Conflicts ------------------------------------------ tidyverse_conflicts() --
## x dplyr::filter() masks stats::filter()
## x dplyr::lag()    masks stats::lag()
library(knitr)

Fase 3 - Questionário:

1) Quantas pinturas existem no MoMA? Quantas variáveis existem no banco de dados?

"Existem 2.253 pinturas no MoMA e no banco de dados existem 25 variáveis."
## [1] "Existem 2.253 pinturas no MoMA e no banco de dados existem 25 variáveis."
table(MOMA$classification) 
## 
## Painting 
##     2253
ncol(MOMA)
## [1] 25

2) Qual é a primeira pintura adquirida pelo MoMA? Qual ano? Qual artista? Qual título?

paste("São", 
      MOMA %>% 
        filter(year_acquired == min(year_acquired, na.rm = T)) %>% 
        nrow(), 
      "as pinturas adquiridas em", 
      MOMA %>% 
        filter(year_acquired == min(year_acquired, na.rm = T)) %>% 
        filter(row_number() == 1) %>% 
        pull(year_acquired))
## [1] "São 2 as pinturas adquiridas em 1930"
cat("Os títulos das pinturas são:", 
    MOMA %>% 
      filter(year_acquired == min(year_acquired, na.rm = T)) %>% 
      pull(title) %>% 
      first(), 
    "e", 
    MOMA %>% 
      filter(year_acquired == min(year_acquired, na.rm = T)) %>% 
      pull(title) %>% 
      last(), 
    ", dos artistas", 
    MOMA %>% 
      filter(year_acquired == min(year_acquired, na.rm = T)) %>% 
      pull(artist) %>% 
      first(), 
    "e", 
    MOMA %>% 
      filter(year_acquired == min(year_acquired, na.rm = T)) %>% 
      pull(artist) %>% 
      last())
## Os títulos das pinturas são: House by the Railroad e Seated Nude , dos artistas Edward Hopper e Bernard Karfiol
table(MOMA$year_acquired)
## 
## 1930 1931 1932 1934 1935 1936 1937 1938 1939 1940 1941 1942 1943 1944 1945 1946 
##    2    2    1   14   22   18   19    8   31   18   39   71   22   17   15    5 
## 1947 1948 1949 1950 1951 1952 1953 1954 1955 1956 1957 1958 1959 1960 1961 1962 
##   14   11   29   23   27   20   22   30   36   42   18   39   37   34   45   21 
## 1963 1964 1965 1966 1967 1968 1969 1970 1971 1972 1973 1974 1975 1976 1977 1978 
##   33   36   38   23   65   20   45   37   28    7   16   11   24   19   17   21 
## 1979 1980 1981 1982 1983 1984 1985 1986 1987 1988 1989 1990 1991 1992 1993 1994 
##   71   20   23   20   30   15   86   15   11    8    7   26   67   30    7   41 
## 1995 1996 1997 1998 1999 2000 2001 2002 2003 2004 2005 2006 2007 2008 2009 2010 
##   13   33   21   26   24   29   11   25    4   27   67   21   13   55   21   18 
## 2011 2012 2013 2014 2015 2016 2017 
##   27   27   22   20   21   33   17
MOMA[33:33,c("year_acquired","artist","title")]
## # A tibble: 1 x 3
##   year_acquired artist        title                
##           <dbl> <chr>         <chr>                
## 1          1930 Edward Hopper House by the Railroad
MOMA[42:42,c("year_acquired","artist","title")]
## # A tibble: 1 x 3
##   year_acquired artist          title      
##           <dbl> <chr>           <chr>      
## 1          1930 Bernard Karfiol Seated Nude

3) Qual é a pintura mais antiga da coleção? Qual ano? Qual artista? Qual título?

cat(paste("A pintura mais antiga da coleção no MoMA é do ano de", 
      min(MOMA$year_created, na.rm = T), 
      ", do artista", 
      MOMA %>% 
        filter(year_created == min(year_created, na.rm = T)) %>% 
        pull(artist), 
      "com título", 
      MOMA %>% 
        filter(year_created == min(year_created, na.rm = T)) %>% 
        pull(title)))
## A pintura mais antiga da coleção no MoMA é do ano de 1872 , do artista Odilon Redon com título Landscape at Daybreak
table(MOMA$year_created)
## 
## 1872 1875 1879 1882 1883 1885 1886 1887 1888 1889 1890 1891 1892 1893 1894 1895 
##    1    6    2    1    2    2    1    2    4    5    2    1    2    3    2    3 
## 1896 1897 1898 1899 1900 1901 1902 1903 1904 1905 1906 1907 1908 1909 1910 1911 
##    1    2    1    2    6    1    2    1    1   11    6   15   14   12   18   19 
## 1912 1913 1914 1915 1916 1917 1918 1919 1920 1921 1922 1923 1924 1925 1926 1927 
##   33   21   37   18   11   14   13    9   11   13   13   11   14   25   23   27 
## 1928 1929 1930 1931 1932 1933 1934 1935 1936 1937 1938 1939 1940 1941 1942 1943 
##   32   22   21   13   21   13   13   16   15   18   24   26   56   24   31   18 
## 1944 1945 1946 1947 1948 1949 1950 1951 1952 1953 1954 1955 1956 1957 1958 1959 
##   28   13   22   18   25   32   37   16   27   27   23   28   34   32   26   42 
## 1960 1961 1962 1963 1964 1965 1966 1967 1968 1969 1970 1971 1972 1973 1974 1975 
##   39   50   49   44   56   36   36   26   40   29   17   13   19   16   26   19 
## 1976 1977 1978 1979 1980 1981 1982 1983 1984 1985 1986 1987 1988 1989 1990 1991 
##   26   57   13   23   10   27   13   13   31   15   12   24   11   12    5    9 
## 1992 1993 1994 1995 1996 1997 1998 1999 2000 2001 2002 2003 2004 2005 2006 2007 
##    9    6    9    5    6   10    4    3   10    8    7    5    6   19    6    4 
## 2008 2009 2010 2011 2012 2013 2014 2015 2016 2017   NA 
##   22    6    4   11    5   13    7    6    2    2    5
MOMA[697:697,c("year_created","artist","title")] 
## # A tibble: 1 x 3
##   year_created artist       title                
##   <chr>        <chr>        <chr>                
## 1 1872         Odilon Redon Landscape at Daybreak

4) Quantos artistas distintos existem?

paste("Existem ", 
      MOMA %>% 
        count(artist) %>% 
        count() %>% 
        pull(n),
      "artistas distintos no MoMA.")
## [1] "Existem  989 artistas distintos no MoMA."
length(unique(MOMA$artist))
## [1] 989

5) Qual artista tem mais pinturas na coleção?

paste(MOMA %>% 
        count(artist) %>% 
        arrange(-n) %>% 
        pull(artist) %>% 
        first(),
      "é o artista com mais pinturas na coleção.")
## [1] "Pablo Picasso é o artista com mais pinturas na coleção."
sort(table(MOMA$artist),decreasing=TRUE)[1:1]
## Pablo Picasso 
##            55

6) Quantas pinturas existem por este artista?

paste("Existem", MOMA %>% 
        count(artist) %>% 
        arrange(-n) %>% 
        pull(n) %>% 
        first(),
      "Pinturas.")
## [1] "Existem 55 Pinturas."

7) Quantas pinturas de artistas masculinos e femininos?

paste("Existem", MOMA %>% 
        count(n_female_artists) %>% 
        arrange(-n) %>% 
        pull(n) %>% 
        first(),
      "pinturas de artistas masculinos e 255 de pinturas de artistas femininas.")
## [1] "Existem 1998 pinturas de artistas masculinos e 255 de pinturas de artistas femininas."
MOMA %>%
  count(artist_gender) %>%
  mutate(n = as.character(paste(n, "pinturas"))) %>% 
  kable() 
artist_gender n
FEMININO 255 pinturas
MASCULINO 1998 pinturas
table(MOMA$artist_gender)
## 
##  FEMININO MASCULINO 
##       255      1998

8) Quantos artistas de cada gênero existem?

MOMA %>%
  count(artist_gender, artist) %>% 
  count(artist_gender) %>% 
  mutate(n = as.character(paste(n, "artistas"))) %>% 
  kable()
artist_gender n
FEMININO 146 artistas
MASCULINO 843 artistas

9) Em que ano foram adquiridas mais pinturas?

paste("Existem", MOMA %>% 
        count(year_acquired) %>% 
        arrange(-n) %>% 
        pull(n) %>% 
        first(),
      "Pinturas no ano de",
      MOMA %>% 
        count(year_acquired) %>% 
        arrange(-n) %>% 
        pull(year_acquired) %>% 
        first())
## [1] "Existem 86 Pinturas no ano de 1985"
sort(table(MOMA$year_acquired),decreasing=TRUE)[1:1]
## 1985 
##   86

10) Em que ano foram Criada mais pinturas?

paste("Foram criadas", MOMA %>% 
        count(year_created) %>% 
        arrange(-n) %>% 
        pull(n) %>% 
        first(),
      "pinturas no ano de",
       MOMA %>% 
        count(year_created) %>% 
        arrange(-n) %>% 
        pull(year_created) %>% 
        first())
## [1] "Foram criadas 57 pinturas no ano de 1977"
sort(table(MOMA$year_created),decreasing=TRUE)[1:1]
## 1977 
##   57

11) Em que ano foi adquirida a primeira pintura de uma artista feminina (solo)? Quando essa pintura foi criada? Qual artista? Qual título?

"A primeira pintura de uma artista feminina foi adquirida em 1937 da artista Natalia Goncharova com o título Landscape, 47 criada em 1912."
## [1] "A primeira pintura de uma artista feminina foi adquirida em 1937 da artista Natalia Goncharova com o título Landscape, 47 criada em 1912."
MOMA[333:333,c("year_created","artist","title","year_acquired")]  
## # A tibble: 1 x 4
##   year_created artist             title         year_acquired
##   <chr>        <chr>              <chr>                 <dbl>
## 1 1912         Natalia Goncharova Landscape, 47          1937

12) Qual o artista ficou mais tempo vivo?

"A artista que ficou mais tempo viva foi a Dorothea Tanning com 102 anos de idade"
## [1] "A artista que ficou mais tempo viva foi a Dorothea Tanning com 102 anos de idade"
MOMA[2054:2054,c("artist","age","artist_gender")]
## # A tibble: 1 x 3
##   artist             age artist_gender
##   <chr>            <dbl> <chr>        
## 1 Dorothea Tanning   102 FEMININO
table(MOMA$age,MOMA$n_female_artists)
##      
##        0  1  2
##   27   2  0  0
##   28   1  0  0
##   29   1  0  0
##   30   2  0  0
##   31   0  1  0
##   32   4  1  0
##   34  12  3  0
##   35   2  2  0
##   36   6  0  0
##   37   4  0  0
##   38   3  0  0
##   39   1  0  0
##   40   7  0  0
##   41   3  1  0
##   42   1  0  0
##   43   2  0  0
##   44  31  0  0
##   45   1  0  0
##   46   1  0  0
##   47   6  3  0
##   48   6  0  0
##   49   0  1  0
##   50  11  1  0
##   51  14  0  0
##   52  15  3  0
##   53   3  0  0
##   54  20  3  0
##   55  17  1  0
##   56  10  0  0
##   57  12  0  0
##   58   9  0  0
##   59  28  0  0
##   60   3  0  0
##   61  18  0  0
##   62   7  1  0
##   63   8  3  0
##   64  12  3  0
##   65  29  2  0
##   66  34  0  0
##   67  55 17  0
##   68  15  4  0
##   69  29  4  0
##   70  20  0  0
##   71  33  0  0
##   72  43  3  0
##   73  23  6  0
##   74  75  2  0
##   75  38  1  0
##   76  61  3  0
##   77  30  0  0
##   78  47  1  0
##   79  27  0  0
##   80  45  1  0
##   81  28  3  0
##   82  29  1  0
##   83  79  5  0
##   84  41  5  0
##   85  81  1  0
##   86  68  5  0
##   87  22  2  0
##   88  26  2  0
##   89  25  8  0
##   90  50  0  0
##   91  26  1  0
##   92  79  9  0
##   93  20  1  0
##   94  13  2  0
##   95   4  1  0
##   96   8  2  0
##   97   2  0  0
##   98   7  0  0
##   99   2  4  0
##   101  2  1  0
##   102  0  1  0

13) Qual a idade média de um artista?

MOMA$age <- as.factor(MOMA$age)

"A idade média de um artista é de 75 anos"
## [1] "A idade média de um artista é de 75 anos"
"   age          
 Min.   : 27.00     
 1st Qu.: 67.00     
 Median : 77.00     
 Mean   : 74.66     
 3rd Qu.: 85.00     
 Max.   :102.00     
 NA's   :629    "                        
## [1] "   age          \n Min.   : 27.00     \n 1st Qu.: 67.00     \n Median : 77.00     \n Mean   : 74.66     \n 3rd Qu.: 85.00     \n Max.   :102.00     \n NA's   :629    "

14) Artistas homens vivem mais do que as mulheres?

"Os homens artistas nessa amostra vive mais do que as mulhres"
## [1] "Os homens artistas nessa amostra vive mais do que as mulhres"
"MUlheres"
## [1] "MUlheres"
table(MOMA$age,MOMA$n_female_artists)
##      
##        0  1  2
##   27   2  0  0
##   28   1  0  0
##   29   1  0  0
##   30   2  0  0
##   31   0  1  0
##   32   4  1  0
##   34  12  3  0
##   35   2  2  0
##   36   6  0  0
##   37   4  0  0
##   38   3  0  0
##   39   1  0  0
##   40   7  0  0
##   41   3  1  0
##   42   1  0  0
##   43   2  0  0
##   44  31  0  0
##   45   1  0  0
##   46   1  0  0
##   47   6  3  0
##   48   6  0  0
##   49   0  1  0
##   50  11  1  0
##   51  14  0  0
##   52  15  3  0
##   53   3  0  0
##   54  20  3  0
##   55  17  1  0
##   56  10  0  0
##   57  12  0  0
##   58   9  0  0
##   59  28  0  0
##   60   3  0  0
##   61  18  0  0
##   62   7  1  0
##   63   8  3  0
##   64  12  3  0
##   65  29  2  0
##   66  34  0  0
##   67  55 17  0
##   68  15  4  0
##   69  29  4  0
##   70  20  0  0
##   71  33  0  0
##   72  43  3  0
##   73  23  6  0
##   74  75  2  0
##   75  38  1  0
##   76  61  3  0
##   77  30  0  0
##   78  47  1  0
##   79  27  0  0
##   80  45  1  0
##   81  28  3  0
##   82  29  1  0
##   83  79  5  0
##   84  41  5  0
##   85  81  1  0
##   86  68  5  0
##   87  22  2  0
##   88  26  2  0
##   89  25  8  0
##   90  50  0  0
##   91  26  1  0
##   92  79  9  0
##   93  20  1  0
##   94  13  2  0
##   95   4  1  0
##   96   8  2  0
##   97   2  0  0
##   98   7  0  0
##   99   2  4  0
##   101  2  1  0
##   102  0  1  0
"Homens"
## [1] "Homens"
table(MOMA$age,MOMA$n_male_artists)
##      
##        0  1  2  3  9
##   27   0  2  0  0  0
##   28   0  1  0  0  0
##   29   0  1  0  0  0
##   30   0  2  0  0  0
##   31   1  0  0  0  0
##   32   1  4  0  0  0
##   34   3 12  0  0  0
##   35   2  2  0  0  0
##   36   0  6  0  0  0
##   37   0  4  0  0  0
##   38   0  3  0  0  0
##   39   0  1  0  0  0
##   40   0  7  0  0  0
##   41   1  3  0  0  0
##   42   0  1  0  0  0
##   43   0  2  0  0  0
##   44   0 31  0  0  0
##   45   0  1  0  0  0
##   46   0  1  0  0  0
##   47   3  6  0  0  0
##   48   0  6  0  0  0
##   49   1  0  0  0  0
##   50   1 11  0  0  0
##   51   0 14  0  0  0
##   52   3 15  0  0  0
##   53   0  3  0  0  0
##   54   3 20  0  0  0
##   55   1 17  0  0  0
##   56   0 10  0  0  0
##   57   0 12  0  0  0
##   58   0  9  0  0  0
##   59   0 28  0  0  0
##   60   0  3  0  0  0
##   61   0 18  0  0  0
##   62   0  7  0  0  1
##   63   3  8  0  0  0
##   64   3 12  0  0  0
##   65   2 29  0  0  0
##   66   0 34  0  0  0
##   67  17 55  0  0  0
##   68   3 16  0  0  0
##   69   4 29  0  0  0
##   70   0 20  0  0  0
##   71   0 33  0  0  0
##   72   3 43  0  0  0
##   73   6 23  0  0  0
##   74   2 75  0  0  0
##   75   1 38  0  0  0
##   76   3 61  0  0  0
##   77   0 30  0  0  0
##   78   1 47  0  0  0
##   79   0 27  0  0  0
##   80   1 45  0  0  0
##   81   3 28  0  0  0
##   82   1 29  0  0  0
##   83   5 79  0  0  0
##   84   5 41  0  0  0
##   85   1 81  0  0  0
##   86   5 67  1  0  0
##   87   2 22  0  0  0
##   88   2 26  0  0  0
##   89   8 25  0  0  0
##   90   0 50  0  0  0
##   91   1 26  0  0  0
##   92   9 79  0  0  0
##   93   1 20  0  0  0
##   94   2 13  0  0  0
##   95   1  4  0  0  0
##   96   2  8  0  0  0
##   97   0  2  0  0  0
##   98   0  7  0  0  0
##   99   4  2  0  0  0
##   101  1  2  0  0  0
##   102  1  0  0  0  0

Recriar o gráfico do fivethirtyeight

moma_dim <- MOMA %>% 
  filter(height_cm < 600, width_cm < 760) %>% 
  mutate(hw_ratio = height_cm / width_cm,
         hw_cat = case_when(
           hw_ratio > 1 ~ "mais alto que largo",
           hw_ratio < 1 ~ "mais largo que alto",
           hw_ratio == 1 ~ "quadrado perfeito"
         ))
library(ggthemes)
ggplot(moma_dim, aes(x = width_cm, y = height_cm, colour = hw_cat)) +
  geom_point(alpha = .5) +
  ggtitle("Pinturas do MoMA, altas e largas") +
  scale_colour_manual(name = "",
                      values = c("#11731d", "#b52b2b", "blue")) +
  theme_fivethirtyeight() +
  theme(axis.title = element_text()) +
  labs(x = "Largura", y = "Altura")