I used ggplot to make a like graph with two variables, but I need to add a secondary y-axis and assign it to one of the variables ("volt").
I also would like to specify the range of the secondary y-axis (upper and lower limit), as well as the breaks - as I did for the y-main-axis.
My two variables are "Sr" and "volt".
I don't want to use different dataframes and then merge the graphs.
Do any of you know how to do it? Oh, I must add that I am an absolute beginner!
Thanks, Pedro
ggplot(data = k, aes(x = Dist)) +
geom_line(aes(y = Sr), colour="blue") +
geom_line(aes(y = volt), colour = "grey") +
xlab(bquote('Distance-um')) +
ylab(bquote('Sr87Sr86')) +
geom_point(aes(y = Sr), colour="black", size=2) +
geom_point(aes(y = volt), colour="grey", size=2) +
theme(axis.title.x = element_text(colour="black",size=10,face="bold"),
axis.title.y = element_text(colour="black",size=10,face="bold"),
axis.text.x = element_text(colour="black",size=8, face="plain"),
axis.text.y = element_text(colour="black",size=8, face="plain")) +
theme(panel.background = element_rect(fill = "white")) +
theme(panel.grid.major = element_blank(),
panel.grid.minor = element_blank(),
strip.background = element_blank(),
panel.border = element_rect(colour = "black", fill="transparent")) +
theme(plot.title = element_text(lineheight=.8, size=10, face="bold")) +
geom_hline(aes(yintercept=0.7061), colour="black", linetype="dotted") +
geom_hline(aes(yintercept=0.7078), colour="black", linetype="dotted") +
geom_hline(aes(yintercept=0.70467), colour="black", linetype="dotted") +
scale_x_continuous(limits=c(-0.01, 1000), breaks=c(0, 250, 500, 750, 1000))+
scale_y_continuous(limits=c(0.7039, 0.7101), breaks=c(0.7040, 0.7050,
0.7060, 0.7070, 0.7080, 0.7090)) +
theme(plot.margin = unit(c(.25,.25,.0,.0), "cm"))