Flip graph so lowest y-value is at the top?

Hi there,

I am trying to create a graph that shows how dissolved oxygen (DO) changes throughout the water column as you go deeper. To better illustrate this, I want to surface of the column (y = 0) to be at the top, and I want the x-axis (DO) to be at the top of the graph.

Currently, the graph looks like this:

I want to essentially flip it so that it looks like you are looking at a slice of the water column from the surface to the bottom. I have searched online and other forums to try and figure it out, but I haven't been successful in finding anything. If anyone knows any advanced ggplot() techniques, that would be super helpful!

Here is the data I used to make this graph:

data <- structure(list(SITE_ID = c("GBA20-10501", "GBA20-10501", "GBA20-10501", 
"GBA20-10501", "GBA20-10501", "GBA20-10501", "GBA20-10501", "GBA20-10501", 
"GBA20-10501", "GBA20-10501", "GBA20-10501", "GBA20-10501", "GBA20-10501"
), DEPTH = c(0.1, 0.5, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11), LINE = c(13.5, 
13.5, 13.5, 13.5, 13.5, 13.5, 13.5, 13.5, 13.5, 13.5, 13.5, 13.5, 
13.5), TEMPERATURE = c(21.95, 21.9, 21.9, 21.85, 21.7, 21.65, 
21.55, 21.3, 20.35, 18.3, 16.8, 15.95, 15.7), DO = c(9.6, 9.6, 
9.7, 9.55, 9.45, 9.3, 8.95, 8.6, 6.55, 4.85, 2.35, 2.05, 2), 
    PH = c(8.64, 8.64, 8.645, 8.64, 8.62, 8.6, 8.565, 8.485, 
    8.255, 8.06, 7.955, 7.94, 7.935), CONDUCTIVITY = c(309.75, 
    309.75, 309.75, 309.6, 310.05, 310.65, 310.35, 310.6, 309, 
    299.95, 292.55, 287.55, 287.8), LIGHT_AMB = c(204.15, 204.35, 
    204.2, 204.15, 204.25, 204.3, 204.25, 204.15, 204.4, 204.1, 
    204.15, 204.2, 204.15), LIGHT_UW = c(985.4, 853.1, 834.5, 
    332.65, 124.7, 64.55, 31.1, 15.05, 7.65, 3.8, 2.25, 0.9, 
    0.25), FRLIGHT = c(4.82684300759246, 4.17470026914607, 4.08667972575906, 
    1.62943913788881, 0.610526315789474, 0.315956926089085, 0.152264381884945, 
    0.0737203036982611, 0.037426614481409, 0.0186183243508084, 
    0.0110213078618663, 0.00440744368266406, 0.00122458976242959
    )), row.names = c(NA, -13L), class = c("grouped_df", "tbl_df", 
"tbl", "data.frame"), groups = structure(list(SITE_ID = "GBA20-10501", 
    .rows = structure(list(1:13), ptype = integer(0), class = c("vctrs_list_of", 
    "vctrs_vctr", "list"))), row.names = c(NA, -1L), class = c("tbl_df", 
"tbl", "data.frame"), .drop = TRUE), na.action = structure(c(`14` = 14L), class = "omit"))

library(ggplot2)
do <- data %>% ggplot() + geom_line(aes(x=DO, y=DEPTH)) + labs(title = "Dissolved Oxygen (mg/L)") +
  coord_cartesian(xlim=c(0,15), ylim=NULL)

I'm going to continue looking for a solution, but in the event I don't find one, any help would be greatly appreciated!

Thanks so much!

add

+ scale_y_reverse()
1 Like

omg I can't believe how simple that was... I clearly was not searching the right keywords. Thank you so much!!

This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.

If you have a query related to it or one of the replies, start a new topic and refer back with a link.