-
Notifications
You must be signed in to change notification settings - Fork 1
/
x-axis-with-vertical-lines.R
109 lines (98 loc) · 1.61 KB
/
x-axis-with-vertical-lines.R
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
library(tidyverse)
library(gapminder)
gdp_data <-
gapminder |>
filter(year == 2007) |>
select(
country,
gdpPercap
) |>
mutate(country = fct_reorder(
country,
gdpPercap
)) |>
arrange(desc(gdpPercap)) |>
slice(1:15)
ggplot(
gdp_data,
aes(
x = gdpPercap,
y = country
)
) +
geom_col()
ggplot(
gdp_data,
aes(
x = gdpPercap,
y = country
)
) +
geom_col() +
theme_minimal() +
theme(
panel.grid.major = element_blank(),
panel.grid.minor = element_blank()
)
ggplot(
gdp_data,
aes(
x = gdpPercap,
y = country
)
) +
geom_col() +
geom_vline(
xintercept = seq(
from = 10000,
to = 50000,
by = 10000
),
color = "white"
) +
theme_minimal() +
theme(
panel.grid.major = element_blank(),
panel.grid.minor = element_blank()
)
ggplot(
gdp_data,
aes(
x = gdpPercap,
y = country
)
) +
geom_col(fill = "#6cabdd") +
geom_vline(
xintercept = seq(
10000,
50000,
by = 10000
),
color = "white"
) +
scale_x_continuous(
expand = expansion(add = 500),
labels = scales::dollar_format(scale = 1 / 1000, suffix = "k")
) +
labs(
x = NULL,
y = NULL,
title = "GDP Per Capita (2007)",
caption = "Source: Gapminder"
) +
theme_minimal(
base_family = "Roboto",
base_size = 14
) +
theme(
panel.grid.major = element_blank(),
panel.grid.minor = element_blank(),
plot.title = element_text(face = "bold"),
plot.caption = element_text(
size = 10,
color = "#7f8c8d",
hjust = 0,
margin = margin(t = 15)
)
)