I would like to plot my data using 2 different y axis. There have been similar questions but the solution doesn't work for me.
my data is similar to this:
d<- data.frame(location = c("Italy", "Italy", "Germany","Germany", "France", "France"),
label = c("Test","Control","Test","Control", "Test","Control"),
a = c(2000,3000, 3000, 4000, 2500, 3500),
b = c(1.5,2,2.5,2, 1.8, 3))
For now this is my solution:
p <- ggplot(d, aes(x = location))
p <- p + geom_bar(aes(y = a, fill = label, group = label, colour = label), stat = "identity",position = "dodge")
p <- p +geom_line(aes(y = b, group = label, colour = label), stat="identity", size = 0.8)+ geom_point(aes(y = b, group = label, colour = label), stat="identity")
p <- p + scale_y_continuous(sec.axis = sec_axis(~ . /2000, name = "b"))+ scale_color_manual(values=c('#7E261A','#15656A'))
I need to compare the values between Test and control group, which is hwy I am using group = label, colour = label), stat="identity"
However, the secondary metric(b) does't show as intended.