Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
M
mooc-rr
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
55066b9debf86be253468bbb91c0a965
mooc-rr
Commits
cf65a3b3
Commit
cf65a3b3
authored
Jun 23, 2020
by
aaaaaa
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Modif reproduction graphe (annotation_custom a la place de geom_curve + text sizing)
parent
f88d413a
Changes
1
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
57 additions
and
17 deletions
+57
-17
exercice_fr.Rmd
module3/exo3/exercice_fr.Rmd
+57
-17
No files found.
module3/exo3/exercice_fr.Rmd
View file @
cf65a3b3
...
...
@@ -140,43 +140,83 @@ p
```
Pour la frise chronologique des rois et reines, nous allons utiliser les données disponibles [ici](https://mbostock.github.io/protovis/ex/wheat.js), et formattées au format CSV.
```{r message=FALSE
, warning=FALSE
}
```{r message=FALSE}
# Fichier des rois et reines
wheat_monarchs <- read_csv("wheat_monarchs.csv")
wheat_monarchs %>%
kable(format = "html", escape = FALSE, align ="c") %>%
kable_styling(bootstrap_options = "striped", full_width = FALSE, position = "left")
```
# Ajout frise chronologique des rois et reines
- Ajout frise chronologique des rois et reines
```{r warning=FALSE}
p <- p +
# rois/reines sur la barre supérieure
geom_rect(data = wheat_monarchs %>% filter(row_number() %% 2 == 1, is.na(commonwealth)), aes(xmin = start, xmax = end, ymin = 97, ymax = 98), inherit.aes = FALSE) +
geom_text(data = wheat_monarchs %>% filter(row_number() %% 2 == 1, is.na(commonwealth)), aes(x = start + (end -start) / 2,y = 96, label = name), size =
3
, family = "NewCenturySchoolbook", fontface = "italic") +
geom_text(data = wheat_monarchs %>% filter(row_number() %% 2 == 1, is.na(commonwealth)), aes(x = start + (end -start) / 2,y = 96, label = name), size =
2
, family = "NewCenturySchoolbook", fontface = "italic") +
# rois/reines sur la barre inférieure
geom_rect(data = wheat_monarchs %>% filter(row_number() %% 2 == 0, is.na(commonwealth)), aes(xmin = start, xmax = end, ymin = 96, ymax = 97), inherit.aes = FALSE) +
geom_text(data = wheat_monarchs %>% filter(row_number() %% 2 == 0, is.na(commonwealth)), aes(x = start + (end -start) / 2,y = 95, label = name), size =
3
, family = "NewCenturySchoolbook", fontface = "italic") +
geom_text(data = wheat_monarchs %>% filter(row_number() %% 2 == 0, is.na(commonwealth)), aes(x = start + (end -start) / 2,y = 95, label = name), size =
2
, family = "NewCenturySchoolbook", fontface = "italic") +
# cas particulier de Cromwell
geom_rect(data = wheat_monarchs %>% filter(commonwealth), aes(xmin = start, xmax = end, ymin = 97, ymax = 98), inherit.aes = FALSE, fill = "white", color = "black") +
geom_text(data = wheat_monarchs %>% filter(commonwealth), aes(x = start + (end -start) / 2,y = 96, label = name), size = 3, family = "NewCenturySchoolbook", fontface = "italic")
geom_text(data = wheat_monarchs %>% filter(commonwealth), aes(x = start + (end -start) / 2,y = 96, label = name), size = 2, family = "NewCenturySchoolbook", fontface = "italic")
p
```
- Ajout des annotations en bas et à droite du graphe.
**Note** : en utilisant `annotation_custom`, on doit également modifier les marges autour du graphe.
```{r warning=FALSE}
p <- p +
theme(plot.margin = unit(c(1.2,0.8,0.5,0), units = "cm")) +
annotation_custom(grob = grid::textGrob(label = "shillings",
gp = grid::gpar(fontsize = 8, fontface = "italic", fontfamily = "NewCenturySchoolbook")),
xmin = 1844, xmax = 1844, ymin = 100, ymax = 100) +
annotation_custom(grob = grid::textGrob(label = "shillings",
gp = grid::gpar(fontsize = 8, fontface = "italic", fontfamily = "NewCenturySchoolbook")),
xmin = 1841, xmax = 1841, ymin = 0, ymax = 0) +
annotation_custom(grob = grid::textGrob(label = "5 Years each division",
gp = grid::gpar(fontsize = 8, fontface = "italic", fontfamily = "NewCenturySchoolbook")),
xmin = 1650, xmax = 1650, ymin = -5, ymax = -5) +
annotation_custom(grob = grid::textGrob(label = "5 Years each division",
gp = grid::gpar(fontsize = 8, fontface = "italic", fontfamily = "NewCenturySchoolbook")),
xmin = 1785, xmax = 1785, ymin = -5, ymax = -5)
p
```
- Enfin, ajout des annonations en haut du graphe.
```{r warning=FALSE}
# Ajout des siècles
p +
geom_rect(aes(xmin = 1565.5, xmax = 1829.5, ymin = 100, ymax = 109), fill = "white") +
annotate(geom = "text",
x = c(1580, 1650, 1750, 1820), y = 101.5,
label = c("16th Century", "17th Century", "18th Century", "19th Century"),
size = 2.7, family = "NewCenturySchoolbook") +
geom_curve(aes(x = 1565, y = 105, xend = 1600, yend = 100), curvature = -0.1, size = 1) +
geom_curve(aes(x = 1600, y = 100, xend = 1700, yend = 100), curvature = -0.17, size = 1) +
geom_curve(aes(x = 1700, y = 100, xend = 1800, yend = 100), curvature = -0.17, size = 1) +
geom_curve(aes(x = 1800, y = 100, xend = 1830, yend = 105), curvature = -0.1, size = 1) +
annotate(geom = "text", x = 1700, y = 104, label = "N°1",
size = 4, family = "NewCenturySchoolbook", fontface = "bold")
annotation_custom(grob = grid::textGrob(label = "16th Century",
gp = grid::gpar(fontsize = 8, fontfamily = "NewCenturySchoolbook")),
xmin = 1577, xmax = 1577, ymin = 102.5, ymax = 102.5) +
annotation_custom(grob = grid::textGrob(label = "17th Century",
gp = grid::gpar(fontsize = 8, fontfamily = "NewCenturySchoolbook")),
xmin = 1650, xmax = 1650, ymin = 102.5, ymax = 102.5) +
annotation_custom(grob = grid::textGrob(label = "18th Century",
gp = grid::gpar(fontsize = 8, fontfamily = "NewCenturySchoolbook")),
xmin = 1750, xmax = 1750, ymin = 102.5, ymax = 102.5) +
annotation_custom(grob = grid::textGrob(label = "19th Century",
gp = grid::gpar(fontsize = 8, fontfamily = "NewCenturySchoolbook")),
xmin = 1820, xmax = 1820, ymin = 102.5, ymax = 102.5) +
annotation_custom(grob = grid::curveGrob(x1 = 0, y1 = 1, x2 = 1, y2 = 0, curvature = -0.12, square = FALSE, ncp = 20,
gp = grid::gpar(col = "black", lwd = 3)),
xmin = 1565, xmax = 1600, ymin = 105, ymax = 100) +
annotation_custom(grob = grid::curveGrob(x1 = 0, y1 = 0, x2 = 1, y2 = 1, curvature = -0.15, square = FALSE, ncp = 20,
gp = grid::gpar(col = "black", lwd = 3)),
xmin = 1600, xmax = 1700, ymin = 100, ymax = 100) +
annotation_custom(grob = grid::curveGrob(x1 = 0, y1 = 0, x2 = 1, y2 = 1, curvature = -0.15, square = FALSE, ncp = 20,
gp = grid::gpar(col = "black", lwd = 3)),
xmin = 1700, xmax = 1800, ymin = 100, ymax = 100) +
annotation_custom(grob = grid::curveGrob(x1 = 0, y1 = 0, x2 = 1, y2 = 1, curvature = -0.12, square = FALSE, ncp = 20,
gp = grid::gpar(col = "black", lwd = 3)),
xmin = 1800, xmax = 1830, ymin = 100, ymax = 105) +
annotation_custom(grob = grid::textGrob(label = "N°1",
gp = grid::gpar(fontsize = 11, fontfamily = "NewCenturySchoolbook", fontface = "bold")),
xmin = 1700, xmax = 1700, ymin = 104, ymax = 104)
```
Ces différentes étapes permettent d'obtenir un graphique assez proche de celui de William Playfair.
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment