Connect points in ggplot in order of position on the y-axis

Viewed 646

enter link description hereI would like to connect points in ggplot with reference to DEPTH(m) (y-axis) NOT with reference to VMR (x-axis).

enter image description here enter image description here

This is the code I am using:

 sp<- ggplot(profiles, aes(x=mean_VLP_ml/avg_cells_ml, y=depth_m)) +
         geom_point(aes(col=avg_cells_ml, size=mean_VLP_ml)) +
         ggtitle("Virus to microbe ratio (VMR) with depth (m)") + 
         xlab("VMR") +
         ylab("Depth_m") + 
         theme(axis.title.y = element_blank()) + scale_y_reverse() +
         expand_limits(y=c(3, 21))

How can I achieve this? I have attached the dataset with google link.

1 Answers

Without an example of the dataset I'm guessing something along the lines of reordering your data along the y axis and then adding in geom_path...

sp <- profiles %>%
    arrange(depth_m) %>%
    ggplot(aes(x=mean_VLP_ml/avg_cells_ml, y=depth_m)) +
    geom_point(aes(col=avg_cells_ml, size=mean_VLP_ml)) +
    geom_path() +
    ggtitle("Virus to microbe ratio (VMR) with depth (m)") + 
    xlab("VMR") +
    ylab("Depth_m") + 
    theme(axis.title.y = element_blank()) + scale_y_reverse() +
    expand_limits(y=c(3, 21))

Similar to the differences in

sp <- mtcars %>%
  arrange(hp) %>%
  ggplot(aes(x=disp, y=hp)) +
  geom_point() +
  geom_path()

and

sp <- mtcars %>%
  arrange(disp) %>%
  ggplot(aes(x=disp, y=hp)) +
  geom_point() +
  geom_path()
Related