按y轴上的位置顺序连接ggplot中的点

时间:2018-12-18 22:12:54

标签: r ggplot2

enter link description here我想将ggplot中的点连接到DEPTH(m)(y轴),而不是参考VMR(x轴)。

enter image description here enter image description here

这是我正在使用的代码:

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

我该如何实现?我已经用Google链接附加了数据集。

1 个答案:

答案 0 :(得分:0)

在没有数据集示例的情况下,我沿y轴对数据进行重新排序,然后添加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))

类似于

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

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