forked from Tazinho/Advanced-R-Solutions
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.Rmd
executable file
·131 lines (110 loc) · 5.23 KB
/
index.Rmd
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
---
knit: "bookdown::render_book"
title: "Advanced R Solutions"
author: "Malte Grosser, Henning Bumann & Hadley Wickham"
description: "Solutions to the Exercises from Hadley Wickham's book 'Advanced R'."
date: "(updated on `r Sys.Date()`)"
url: 'https\://advanced-r-solutions.rbind.io/'
github-repo: Tazinho/Advanced-R-Solutions
cover-image: images/advrs_cover.png
site: bookdown::bookdown_site
documentclass: krantz
bibliography: packages.bib
biblio-style: apalike
link-citations: yes
---
`r if (knitr::is_latex_output()) '<!--'`
# Welcome {-}
```{r global_options, include=FALSE}
knitr::opts_chunk$set(collapse = TRUE)
```
<img src="images/advrs_cover.png" width="250" height="366" align="right" alt="Cover image" />
This book offers solutions to the exercises from Hadley Wickham's book [Advanced R](https://adv-r.hadley.nz/) (Edition 2). It is work in progress and under active development. The 2nd edition of Advanced R is still being revised, but we hope to provide most of the answers in 2019.
The solutions to the first edition of Advanced R can currently be found at https://advanced-r-solutions-ed1.netlify.com/.
The code for this book can be found on [GitHub](https://github.com/Tazinho/Advanced-R-Solutions.git). Your PRs and suggestions are very welcome.
## License {-}
<a rel="license" href="http://creativecommons.org/licenses/by-nc-sa/4.0/"><img alt="Creative Commons License" style="border-width:0" src="https://i.creativecommons.org/l/by-nc-sa/4.0/88x31.png" /></a><br />This work by Malte Grosser and Henning Bumann is licensed under a <a rel="license" href="http://creativecommons.org/licenses/by-nc-sa/4.0/">Creative Commons Attribution-NonCommercial-ShareAlike 4.0 International License</a>
## Acknowledgements {-}
We would also like to thank everybody else who contributed to this project by fixing typos, grammar or revising exercises: `@3zhang`, `@caijun`, `@dongzhuoer`, `@lotgon`
## Current Progress {-}
```{r, echo = FALSE, cache=FALSE, warning = FALSE, message=FALSE, fig.width = 8, fig.height=10}
library(tibble)
library(dplyr)
library(purrr)
library(tidyr)
library(forcats)
library(ggplot2)
# import from file --------------------------------------------------------
df_long <- read.csv2("progress_data.csv", stringsAsFactors = FALSE,
header = TRUE) %>%
as_tibble() %>%
modify_at("status", factor, levels = c("open", "started", "solved")) %>%
tibble::rowid_to_column("id") %>%
separate(chapter, "nr", sep = " ", remove = FALSE, extra = "drop") %>%
mutate(nr = as.integer(nr),
chapter = factor(chapter),
chapter = fct_reorder(chapter, nr, .desc = TRUE),
part = case_when(nr < 9 ~ "Foundations",
nr < 12 ~ "FP",
nr < 17 ~ "OOP",
nr < 22 ~ "Metapr.",
TRUE ~ "Techn."),
part = factor(part, levels = c("Foundations", "FP", "OOP",
"Metapr.", "Techn.")))
# Intermediate calculations
percent_solved <- mean(df_long$status == "solved", na.rm = TRUE) * 100
# Create Plot
plot_progress <- df_long %>%
ggplot(aes(x = chapter, fill = status, group = -id,
subchapter = subchapter, exercise = exercise,
credits = credits)) +
coord_flip() +
geom_bar(color = "white") +
scale_y_continuous(expand = c(0, 0)) +
theme_bw(base_size = 14) +
theme(legend.position = "bottom",
# legend.justification = c(0, 1),
strip.background = element_rect(fill = "#EFEFEF"),
strip.placement = "outside",
axis.text.x = element_blank(),
axis.text.y = element_text(),
axis.title = element_blank(),
axis.ticks = element_blank(),
# plot.title = element_text(hjust = 2.5),
panel.grid = element_blank(),
panel.border = element_blank(),
panel.background = element_blank()) +
guides(color = FALSE,
fill = guide_legend(nrow = 1)) +
scale_fill_manual(values = c("#F99992", "orange", "#00BFC4")) +
labs(title = paste("Solved Exercises:",
round(percent_solved, 1),
"% (2nd Edition)"),
caption = paste0("(Open: ",
sum(df_long$status == "open"),
" | Started: ",
sum(df_long$status == "started"),
" | Solved: ",
sum(df_long$status == "solved"),
")"),
fill = "Status:")
# Create static plot (including facets for parts)
plot_progress +
facet_grid(part ~ ., scales = "free",
space = "free", switch = "both")
# Create interactive version of plot
# plot_progress %>%
# plotly::ggplotly(tooltip = c("subchapter", "exercise", "credits")) %>%
# plotly::layout(legend = list(orientation = "h",
# xanchor = "left",
# x = 0,
# yanchor = "bottom",
# y = -.05,
# font = list(size = 25)))
```
```{r include=FALSE, eval = FALSE}
# automatically create a bib database for R packages
knitr::write_bib(c(.packages(), 'bookdown', 'knitr', 'rmarkdown'),
'packages.bib')
```
`r if (knitr::is_latex_output()) '-->'`