首页 > 解决方案 > 按 y 轴上的位置顺序连接 ggplot 中的点

问题描述

在此处输入链接描述我想参考 DEPTH(m)(y 轴)而不是参考 VMR(x 轴)连接 ggplot 中的点。

在此处输入图像描述 在此处输入图像描述

这是我正在使用的代码:

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

我怎样才能做到这一点?我已经用谷歌链接附加了数据集。

标签: rggplot2

解决方案


如果没有数据集的示例,我猜测沿着 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()

推荐阅读