Skip to content

Commit 02b0609

Browse files
authored
Add files via upload
updated broken_axis.R
1 parent 401be38 commit 02b0609

File tree

1 file changed

+99
-71
lines changed

1 file changed

+99
-71
lines changed

Scripts/Broken_axis.R

+99-71
Original file line numberDiff line numberDiff line change
@@ -1,71 +1,99 @@
1-
2-
library(tidyverse)
3-
library(patchwork)
4-
library(RColorBrewer)
5-
6-
a <- data.frame(
7-
x = c("a", "b", "c", "d", "e"),
8-
y = c(10, 20, 30, 450, 500)
9-
)
10-
11-
lower <- a %>%
12-
ggplot(aes(x = x, y = y)) +
13-
geom_bar(stat = "identity", aes(fill = x),
14-
width = 0.7, color = "black") +
15-
geom_text(aes(label = y), vjust = -0.2) +
16-
scale_fill_manual(values = brewer.pal(8, "Set2")) +
17-
theme_classic() +
18-
theme(legend.position = "none",
19-
axis.title.y = element_text(hjust =1 )) +
20-
coord_cartesian(ylim = c(0, 50))
21-
22-
upper <- a %>%
23-
ggplot(aes(x = x, y = y)) +
24-
geom_bar(stat = "identity", aes(fill = x),
25-
width = 0.7, color = "black") +
26-
geom_text(aes(label = y), vjust = -0.2) +
27-
scale_fill_manual(values = brewer.pal(8, "Set2")) +
28-
labs(x = NULL,
29-
y = NULL) +
30-
theme_classic() +
31-
theme(legend.position = "none",
32-
axis.line.x = element_blank(),
33-
axis.ticks.x = element_blank(),
34-
axis.text.x = element_blank()) +
35-
coord_cartesian(ylim = c(400, 600))
36-
37-
38-
wrap_plots(upper, lower, nrow = 2) &
39-
theme(axis.text = element_text(color = "black"),
40-
text = element_text(size = 14))
41-
42-
left <- a %>%
43-
ggplot(aes(x = y, y = x)) +
44-
geom_bar(stat = "identity", aes(fill = x),
45-
width = 0.7, color = "black") +
46-
geom_text(aes(label = y), hjust = -0.2) +
47-
scale_fill_manual(values = brewer.pal(8, "Set2")) +
48-
theme_classic() +
49-
theme(legend.position = "none",
50-
axis.title.x = element_text(hjust =1 )) +
51-
coord_cartesian(xlim = c(0, 50))
52-
53-
54-
right <- a %>%
55-
ggplot(aes(x = y, y = x)) +
56-
geom_bar(stat = "identity", aes(fill = x),
57-
width = 0.7, color = "black") +
58-
geom_text(aes(label = y),hjust = -0.2) +
59-
scale_fill_manual(values = brewer.pal(8, "Set2")) +
60-
labs(x = NULL,
61-
y = NULL) +
62-
theme_classic() +
63-
theme(legend.position = "none",
64-
axis.line.y = element_blank(),
65-
axis.ticks.y = element_blank(),
66-
axis.text.y = element_blank()) +
67-
coord_cartesian(xlim = c(400, 600))
68-
69-
wrap_plots(left, right, nrow = 1) &
70-
theme(axis.text = element_text(color = "black"),
71-
text = element_text(size = 14))
1+
2+
library(tidyverse)
3+
library(patchwork)
4+
library(RColorBrewer)
5+
6+
7+
a <- data.frame(
8+
x = c("a", "b", "c", "d", "e"),
9+
y = c(10, 20, 30, 450, 500)
10+
)
11+
12+
lower <- a %>%
13+
ggplot(aes(x = x, y = y)) +
14+
geom_bar(stat = "identity", aes(fill = x),
15+
width = 0.7, color = "black") +
16+
geom_text(aes(label = y), vjust = -0.2) +
17+
scale_fill_manual(values = brewer.pal(8, "Set2")) +
18+
theme_classic() +
19+
theme(legend.position = "none",
20+
axis.title.y = element_text(hjust =1 )) +
21+
coord_cartesian(ylim = c(0, 50))
22+
23+
upper1 <- a %>%
24+
ggplot(aes(x = x, y = y)) +
25+
geom_bar(stat = "identity", aes(fill = x),
26+
width = 0.7, color = "black") +
27+
geom_text(aes(label = y), vjust = -0.2) +
28+
scale_fill_manual(values = brewer.pal(8, "Set2")) +
29+
labs(x = NULL,
30+
y = NULL) +
31+
theme_classic() +
32+
theme(legend.position = "none",
33+
axis.line.x = element_blank(),
34+
axis.ticks.x = element_blank(),
35+
axis.text.x = element_blank()) +
36+
coord_cartesian(ylim = c(400, 550))
37+
38+
upper2 <- a %>%
39+
ggplot(aes(x = x, y = y)) +
40+
geom_bar(stat = "identity", aes(fill = x),
41+
width = 0.7, color = "black") +
42+
geom_text(aes(label = y), vjust = -0.2) +
43+
scale_fill_manual(values = brewer.pal(8, "Set2")) +
44+
labs(x = NULL,
45+
y = NULL) +
46+
theme_classic() +
47+
theme(legend.position = "none",
48+
axis.line.x = element_blank(),
49+
axis.ticks.x = element_blank(),
50+
axis.text.x = element_blank()) +
51+
coord_cartesian(ylim = c(450, 520))
52+
53+
54+
broken1 <- wrap_plots(upper1, lower, nrow = 2) &
55+
theme(axis.text = element_text(color = "black"),
56+
text = element_text(size = 14))
57+
58+
broken2 <- wrap_plots(upper2, lower, nrow = 2) &
59+
theme(axis.text = element_text(color = "black"),
60+
text = element_text(size = 14))
61+
62+
wrap_plots(broken1, broken2, nrow = 1)
63+
64+
ggsave("../Results/Broken_axis.svg", height = 4, width = 6, bg = "white")
65+
ggsave("../Results/Broken_axis.png", height = 4, width = 6, bg = "white")
66+
67+
68+
69+
70+
left <- a %>%
71+
ggplot(aes(x = y, y = x)) +
72+
geom_bar(stat = "identity", aes(fill = x),
73+
width = 0.7, color = "black") +
74+
geom_text(aes(label = y), hjust = -0.2) +
75+
scale_fill_manual(values = brewer.pal(8, "Set2")) +
76+
theme_classic() +
77+
theme(legend.position = "none",
78+
axis.title.x = element_text(hjust =1 )) +
79+
coord_cartesian(xlim = c(0, 50))
80+
81+
82+
right <- a %>%
83+
ggplot(aes(x = y, y = x)) +
84+
geom_bar(stat = "identity", aes(fill = x),
85+
width = 0.7, color = "black") +
86+
geom_text(aes(label = y),hjust = -0.2) +
87+
scale_fill_manual(values = brewer.pal(8, "Set2")) +
88+
labs(x = NULL,
89+
y = NULL) +
90+
theme_classic() +
91+
theme(legend.position = "none",
92+
axis.line.y = element_blank(),
93+
axis.ticks.y = element_blank(),
94+
axis.text.y = element_blank()) +
95+
coord_cartesian(xlim = c(400, 600))
96+
97+
wrap_plots(left, right, nrow = 1) &
98+
theme(axis.text = element_text(color = "black"),
99+
text = element_text(size = 14))

0 commit comments

Comments
 (0)