Skip to content

Commit

Permalink
minor fixes, prepare for production
Browse files Browse the repository at this point in the history
  • Loading branch information
clauswilke committed Jan 14, 2019
1 parent e78628b commit 677aca1
Show file tree
Hide file tree
Showing 5 changed files with 93 additions and 4 deletions.
50 changes: 50 additions & 0 deletions _bookdown_production.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
new_session: yes
output_dir: "_book_production"
delete_merged_file: true

rmd_files: [
"index.Rmd",

"preface.Rmd",
"introduction.Rmd",

# Part I
"aesthetic_mapping.Rmd", # completed
"coordinate_systems_axes.Rmd", # completed
"color_basics.Rmd", # completed
"directory_of_visualizations.Rmd",
"visualizing_amounts.Rmd", # completed
"visualizing_distributions_I.Rmd", # completed
"visualizing_distributions_II.Rmd", # completed
"boxplots_violins.Rmd", # completed
"visualizing_proportions.Rmd", # completed
"nested_proportions.Rmd", # completed
"visualizing_associations.Rmd", # completed
"time_series.Rmd", # completed
"visualizing_trends.Rmd", # completed
"geospatial_data.Rmd", # completed
"visualizing_uncertainty.Rmd", # completed

# Part II

"proportional_ink.Rmd", # completed
"overlapping_points.Rmd", # completed
"pitfalls_of_color_use.Rmd", # completed
"redundant_coding.Rmd", # completed
"multi-panel_figures.Rmd", # completed
"figure_titles_captions.Rmd", # completed
"balance_data_context.Rmd", # completed
"small_axis_labels.Rmd", # completed
"avoid_line_drawings.Rmd", # completed
"no_3d.Rmd", # completed

# Part III
"image_file_formats.Rmd", # completed
"choosing_visualization_software.Rmd", # completed
"telling_a_story.Rmd", # completed
"annotated_bibliography.Rmd",

"technical_notes.Rmd",

"references.Rmd"
]
2 changes: 1 addition & 1 deletion _build_asciidoc.sh
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

echo "Preparing AsciiDoc output"

cd _book_final
cd _book_production
for f in *.md;
do
echo "converting $f"
Expand Down
12 changes: 12 additions & 0 deletions _build_production.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
#!/bin/sh

rm -rf ./_book_production/

mv ./_common.R ./_common_backup.R
cp ./_common_production.R ./_common.R

Rscript -e "bookdown::render_book(input = 'index.Rmd', output_format = 'bookdown::gitbook', config_file = '_bookdown_production.yml')"

mv ./_common_backup.R ./_common.R

./_build_asciidoc.sh
19 changes: 19 additions & 0 deletions _common_production.R
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
set.seed(7654)
options(digits = 3)

knitr::opts_chunk$set(
echo = FALSE,
message = FALSE,
warning = FALSE,
cache = FALSE,
dpi = 210, # this creates 2*210 dpi at 6in, which is 2*300dpi at 4.2in
fig.align = 'center',
fig.width = 6,
fig.asp = 0.618, # 1 / phi
fig.show = "hold"
)

options(dplyr.print_min = 6, dplyr.print_max = 6)

library(dviz.supp)

14 changes: 11 additions & 3 deletions visualizing_proportions.Rmd
Original file line number Diff line number Diff line change
Expand Up @@ -196,7 +196,7 @@ of proportions

## A case for side-by-side bars {#side-by-side-bars}

I will now demonstrate a case where pie charts fail. This example is modeled after a critique of pie charts originally posted on Wikipedia [@Schutz-piecharts]. Consider the hypothetical scenario of five companies, A, B, C, D, and E, who all have roughly comparable market share of approximately 20%. Our hypothetical dataset lists the marketshare of each company for three consecutive years. When we visualize this dataset with pie charts, it is difficult to see what exactly is going on (Figure \@ref(fig:marketshare-pies)). It appears that the market share of company A is growing and the one of company E is shrinking, but beyond this one observation we can't tell what's going on. In particular, it is unclear how exactly the market shares of the different companies compare within each year.
I will now demonstrate a case where pie charts fail. This example is modeled after a critique of pie charts originally posted on Wikipedia [@Schutz-piecharts]. Consider the hypothetical scenario of five companies, A, B, C, D, and E, who all have roughly comparable market share of approximately 20%. Our hypothetical dataset lists the market share of each company for three consecutive years. When we visualize this dataset with pie charts, it is difficult to see what exactly is going on (Figure \@ref(fig:marketshare-pies)). It appears that the market share of company A is growing and the one of company E is shrinking, but beyond this one observation we can't tell what's going on. In particular, it is unclear how exactly the market shares of the different companies compare within each year.


(ref:marketshare-pies) Market share of five hypothetical companies, A--E, for the years 2015--2017, visualized as pie charts. This visualization has two major problems: 1. A comparison of relative market share within years is nearly impossible. 2. Changes in market share across years are difficult to see.
Expand Down Expand Up @@ -246,7 +246,11 @@ The picture becomes a little clearer when we switch to stacked bars (Figure \@re
```{r marketshare-stacked, fig.cap='(ref:marketshare-stacked)'}
stacked_bars <- ggplot(marketshare, aes(x = year, y = percent, fill = company)) +
geom_col(position = "stack") +
scale_y_continuous(expand = c(0, 0)) +
scale_y_continuous(
name = "market share",
labels = scales::percent_format(accuracy = 1, scale = 1),
expand = c(0, 0)
) +
scale_fill_OkabeIto(order = c(1:3, 5, 4)) +
theme_dviz_open() +
theme(plot.margin = margin(14, 7, 3, 0))
Expand All @@ -262,7 +266,11 @@ For this hypothetical data set, side-by-side bars are the best choice (Figure \@
ggplot(marketshare, aes(x = company, y = percent, fill = company)) +
geom_col() +
facet_wrap(~year) +
scale_y_continuous(expand = c(0, 0)) +
scale_y_continuous(
name = "market share",
labels = scales::percent_format(accuracy = 1, scale = 1),
expand = c(0, 0)
) +
scale_fill_OkabeIto(order = c(1:3, 5, 4), guide = "none") +
theme_dviz_open() +
theme(strip.background = element_blank())
Expand Down

0 comments on commit 677aca1

Please sign in to comment.