0

I have a dataframe datas and I want to plot each of my colunm, my code is the following.

Is there a way not to write all the geom_line() for all my colunms because sometimes I will have only 10 columns in my Df

 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"))
zx8754
  • 52,746
  • 12
  • 114
  • 209
  • 2
    Reshape your data from wide-to-long then plot. – zx8754 Jul 25 '18 at 07:28
  • 1
    This is not the `ggplot` way; you should reshape your data from wide to long, and then use the `colour` aesthetic to map different columns to different coloured lines. – Maurits Evers Jul 25 '18 at 07:29

0 Answers0