I'm trying to make a graph with a double y-axis.
My data looks like this:
year variable value
1 2009 Letselongevallen 4455
2 2010 Letselongevallen 4337
3 2011 Letselongevallen 4710
4 2012 Letselongevallen 4666
5 2013 Letselongevallen 4460
6 2014 Letselongevallen 4400
7 2015 Letselongevallen 4284
8 2016 Letselongevallen 4467
9 2017 Letselongevallen 4199
10 2018 Letselongevallen 4433
11 2009 Doden 21
12 2010 Doden 20
13 2011 Doden 22
14 2012 Doden 26
15 2013 Doden 25
16 2014 Doden 30
17 2015 Doden 28
18 2016 Doden 26
19 2017 Doden 17
20 2018 Doden 16
Both "letselongevallen and "doden" need to be on a different axis.
This is the code I wrote
hitrun_graph = ggplot(hitrun_graph1,
aes(x = year,
y = value,
group = variable,
colour = variable)) +
theme_minimal(base_size = 16) +
geom_line(size = 2.25) +
scale_y_continuous(name = "Letselongevallen", limits = c(0,5000),
sec.axis = sec_axis(~./ 142, name = "Doden 30 dagen")) +
scale_fill_manual(ColorsAll) +
labs(x = NULL) +
theme(legend.title = element_blank(),
legend.text=element_text(size = 22),
axis.text.x = element_text(size = 22),
axis.text.y = element_text(size = 22),
legend.position = "right")
This gives me a graph with a double y-axis, but how do I force R to put "Doden" on the axis on the right?
x * 142
. – teunbrandColorsAll
from a package or can you define it please? – markhogue