Nothing
## ----include = FALSE----------------------------------------------------------
knitr::opts_chunk$set(
collapse = TRUE,
comment = "#>"
)
## ----include = FALSE----------------------------------------------------------
x <- 12345689.987654321
## -----------------------------------------------------------------------------
library(scales)
label_number(big.mark = ".", decimal.mark = ",", accuracy = .1)(x)
## -----------------------------------------------------------------------------
library(countryscales)
label_number_de(accuracy = .1)(x)
## ----top-10-pop---------------------------------------------------------------
top10_pop <- gapminder15[order(-gapminder15$pop), c("country", "pop")]
top10_pop$pct <- top10_pop$pop / sum(top10_pop$pop)
top10_pop <- head(top10_pop, 10)
## -----------------------------------------------------------------------------
library(ggplot2)
p <- ggplot(top10_pop, aes(pop, reorder(country, pop))) +
geom_col() +
theme_minimal() +
theme(
panel.grid.major = element_blank(),
panel.grid.minor = element_blank()
) +
labs(
x = NULL, y = NULL,
title = "Top 10 of countries by population size in 2015",
caption = "Data: gapminder.org"
)
## ----style-scales-------------------------------------------------------------
lbl_pct <- label_percent(big.mark = ".", decimal.mark = ",", accuracy = .1)
lbl_num <- label_number(big.mark = ".", decimal.mark = ",")
p +
# Add percentages to bars using German style conventions
geom_text(
aes(label = lbl_pct(pct)),
hjust = 1.1, size = 8 / .pt, color = "white") +
# Format numbers as percentages
scale_x_continuous(
labels = lbl_num,
expand = c(0, 0, .05, 0))
## ----style-countryscales------------------------------------------------------
p +
# Add percentages to bars using German style conventions
geom_text(
aes(
label = label_percent_de(accuracy = .1)(pct)
),
hjust = 1.1, size = 8 / .pt, color = "white"
) +
# Format numbers as percentages
scale_x_number_de(expand = c(0, 0, .05, 0))
Any scripts or data that you put into this service are public.
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.