---
title: "LAB 2: Perception et couleurs"
author: "Antoine Neuraz"
date: "19/11/2019"
output: 
  xaringan::moon_reader:
    css: ['default','css/my_style.css']
    lib_dir: libs
    seal: false
    nature:
      ratio: '4:3'
      countIncrementalSlides: false
      self-contained: true
      beforeInit: "addons/macros.js"
---

```{r setup, include=FALSE}
knitr::opts_chunk$set(echo = TRUE)
library(ggplot2)
library(showtext)
```

---
## Les couleurs dans ggplot2

```{r}
dsamp <- diamonds[sample(nrow(diamonds), 1000), ]
ggplot(dsamp, aes(carat, price)) +
  geom_point(aes(colour = clarity)) +
  scale_color_brewer(palette = "Set3")
```

```{r}

ggplot(dsamp, aes(carat, price)) +
  geom_point(aes(colour = carat))) +
  scale_color_distiller(palette="RdYlBu")
```

```{r}

font_add_google("Gochi Hand", "gochi")
showtext_auto()
annotate_color = "grey50"
font_add_google("Schoolbell", "bell")

midpoint = (max(dsamp$carat)-min(dsamp$carat))/2

ggplot(dsamp, aes(carat, price)) +
  geom_vline(xintercept = midpoint, color = annotate_color) +
  geom_point(aes(colour = carat)) +
  scale_color_gradient2(low = "#d8b365", 
                        mid="#f5f5f5", 
                        high="#5ab4ac", 
                        midpoint = midpoint) +
  annotate("text", 
           x=.78, y=15000, hjust=1, srt=40,
           label ="this is the midpoint",  
           family="bell", 
           color=annotate_color) +
  annotate("curve", 
           x = .8, xend=midpoint-.01, y=15000, yend = 14000,
           curvature = -.5, 
           color=annotate_color ,
           arrow=arrow(length = unit(0.03, "npc") )) + 
  theme_minimal() +
  theme(panel.grid.minor = element_blank(), 
        panel.grid.major.x = element_blank()) + ggthemes::theme_tufte()

```



