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

标签 r ggplot2

<分区>

enter link description here我想引用 DEPTH(m)(y 轴)而不是引用 VMR(x 轴)连接 ggplot 中的点。

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

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

最佳答案

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

关于r - 按 y 轴上的位置顺序连接 ggplot 中的点,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/53841859/

相关文章:

python - 每个 Flask session 存储大量数据或服务连接

r - geom_raster 和 geom_point 的两种颜色渐变

r - 有没有办法使用R来打破图表轴并打破线性回归线?

r - 如何循环创建多个条形图?

r - 将自定义文本插入到ggplot2

r - 如何通过R中的组对geom_boxplot中的x轴重新排序?

r - grepl 与正则表达式

RStudio 服务器上的 R Shiny dev 在应用程序启动时 Shiny 崩溃

r - 使用回收创建矩阵

html - 从字符串中删除 HTML 标签(R 编程)