首页 > 解决方案 > 单个图中的多个列

问题描述

我有一个数据框datas,我想绘制我的每个列,我的代码如下。

有没有办法不geom_line()为我的所有列写所有内容,因为有时我的 Df 中只有 10 列

 library(ggplot2)

 g = ggplot(datas , aes(x = -seq(500,0,by = -1), y= value , color = variable  ) ) +
        geom_line(aes(y = V1, col = "1")) +
        geom_line(aes(y = V2, col = "2")) +
        geom_line(aes(y = V3, col = "3")) +
        geom_line(aes(y = V4, col = "4")) +
        geom_line(aes(y = V5, col = "5")) +
        geom_line(aes(y = V6, col = "6")) +
        geom_line(aes(y = V7, col = "7")) +
        geom_line(aes(y = V8, col = "8")) +
        geom_line(aes(y = V9, col = "9")) +
        geom_line(aes(y = V10, col = "10")) +
        geom_line(aes(y = V11, col = "11")) +
        geom_line(aes(y = V12, col = "12")) +
        geom_line(aes(y = V13, col = "13")) +
        geom_line(aes(y = V14, col = "14")) +
        geom_line(aes(y = V15, col = "15")) +
        geom_line(aes(y = V16, col = "16")) +
        geom_line(aes(y = V17, col = "17")) +
        geom_line(aes(y = V18, col = "18"))

标签: rggplot2

解决方案


推荐阅读