I have created a plot for primary production with ggplot2 using this code
ggplot(x, aes(x = pp.section, y = pp.depth*-1, z= pp.temp, colour = pp.pp_sqm_gr)) +
geom_point()+
stat_contour(z=pp.temp)+
scale_colour_gradient2("PP [mg C/m²]", low="white", high=muted("green"), limits=c(0,200))+
labs(x = "section", y = "depth [m]" , title= "PP (12h)")+
theme_bw(base_size = 12, base_family = "")+
theme(panel.background = element_rect(fill = "grey"),
panel.grid.major = element_line(colour = "white", size=0),
panel.grid.minor = element_line(colour="grey"),
axis.text = element_text(size=10),
axis.title = element_text(size=13),
title = element_text(size=11))
What I want to do: create a overlay plot with a secondary y-axis for temperature. Temperature should be displayed as horizontal contour lines.
As the original dataframe is quite big, I give you an example:
df <- data.frame(pp.section, pp.depth, pp.chla, pp.temp, pp.pp_sqm_gr)
pp.section pp.depth pp.chla pp.temp pp.pp_sqm_gr
1 3 3.5 18.0 26.8
1 10 5.5 17.8 56.4
1 15 20.9 17.0 150.4
1 20 4.3 16.0 90.8
1 25 1.2 16.1 66.9
2 30 1.0 16.2 13.1
2 23 2.2 16.4 20.8
2 14 23.1 17.1 117.9
2 8 11.9 17.9 51.4
3 5 6.8 17.9 22.6
3 11 12.0 17.2 167.1
3 20 5.5 16.2 74.2
3 25 6.7 16.1 62.1
Until now I tried ggplot geom_contour(), stat_contour() and geom_line(). Thanks a lot!