0

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))

: Primary Production

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!

chm
  • 41
  • 5
  • You mean secondary z-axis, right? Please provide your code and sufficient data to produce such a plot. See this FAQ: http://stackoverflow.com/a/5963610/1412059 – Roland Nov 17 '15 at 16:12
  • 2
    The authors of both Lattice and ggplot consider two-ordinate plots to be bad graphics and have traditionally made it difficult to use their tools for evil purposes. You should be able to find work-arounds by doing some searches. – IRTFM Nov 17 '15 at 16:18
  • [Here's an example](https://rpubs.com/kohske/dual_axis_in_ggplot2) of how to get a second y-axis. It's quite involved because you have to override ggplot's inherent approach of preventing you from heading down the road to (data visualization) perdition. – eipi10 Nov 17 '15 at 16:50

0 Answers0