0

I'm trying to replicate this graph I made in Excel here with ggplot. My Data is included here. I have many of the same Excel files that I'd like to make these graphs with as a big batch, otherwise I would just use Excel. I can make the graph very similarly in ggplot with the code below, but I don't know how to make the secondary x axis like I have in Excel to make the graph look right. I'd also like to make the one column in the data that says "System UpLoad Time = Jul 25 2017 18:53:32" as the title of the graph. Is there any way to do this easily?

    dat.m <- melt(TestData, id=c ("Depth", "Temp", "Specific Conductance [µS/cm]", "FlECO-AFL", "Beam Attenuation (1/m)", 
                            "Beam Transmission (%)", "Transmissometer voltage", 
                            "Fluorometer voltage", "CDOM Voltage", "CDOM (mg/m^3)", "Flag"))

ggplot(dat.m, aes(value, Depth, colour = variable)) +
  geom_point() + scale_y_reverse()

EDITS:: I have figured out how to make the graph, thanks for the additional links. Is there a way to add what is in a cell of my data to be included in the title or someplace on the graph? The column that says "System UpLoad Time = Jul 25 2017 18:53:32" is important and needs to be on the graph, though not necessarily the title

The new code is here:

dat.m <- melt(TestData, id=c ("Depth", "Temp", "Temp2", "Specific Conductance [µS/cm]", "FlECO-AFL", "Beam Attenuation (1/m)", 
                            "Beam Transmission (%)", "Transmissometer voltage", 
                            "Fluorometer voltage", "CDOM Voltage", "CDOM (mg/m^3)", "Flag", "Derivedchlorophyll"))

plot<-ggplot(dat.m, aes(value, Depth, colour = variable)) +
  geom_point() + scale_y_reverse()

plot+ scale_x_continuous(
  "PAR", 
  sec.axis = sec_axis(~ . / 56, name = "Chlorophyll
                      Temp")
)
Steve G
  • 85
  • 9
  • 1
    have you seen this: http://ggplot2.tidyverse.org/reference/sec_axis.html – MLavoie Feb 20 '18 at 16:54
  • Possible duplicate of [Plot with 2 y axes, one y axis on the left, and another y axis on the right](https://stackoverflow.com/questions/3099219/plot-with-2-y-axes-one-y-axis-on-the-left-and-another-y-axis-on-the-right) – Jan Boyer Feb 20 '18 at 17:37
  • Thank you, this helped and I've edited my post to show what I changed. Any thoughts on the second part of my question, clarified now in my edits? – Steve G Feb 20 '18 at 20:34
  • To clarify even more, it'd be nice to have that info below the graph. I know I can place text using `grid.text((paste("TEXT")), just = c("center", "bottom"), gp = gpar(fontface = "bold", fontsize = 18, col = "blue"))` but how do I go about adding that text from that cell in my data automatically? @MLavoie @JanBoyer – Steve G Feb 20 '18 at 21:14

0 Answers0