0

i have a table like that :

  txchrom position aregion  cover.3.  cover.4.  cover.5.  cover.6.
1     Chr1    10000       1 0.9784159 0.9721487 0.5981375 0.9132184
2     Chr1    20000       1 1.0863354 1.1126714 0.5539226 1.1368213
3     Chr1    30000       1 1.2473976 0.8157534 0.5298649 1.1845525
4     Chr1    40000       1 1.2364256 0.7356141 0.6598456 0.8775449
5     Chr1    50000       1 0.6970729 0.4664318 0.3653256 0.5954298
6     Chr1    60000       1 0.6122086 0.5031472 0.2324904 0.6616862
7     Chr1    70000       1 0.7551553 0.6788025 0.4354427 0.6946689
8     Chr1    80000       1 1.0065884 0.9707345 0.8338270 0.9644197
9     Chr1    90000       1 0.6890880 0.6679611 0.4118416 0.8105101
10    Chr1   100000       1 0.6825312 0.6406786 0.3253632 0.7034053

and i would like to create a line plot in which i will represent with different lines each coverrage (cover.3, cover.4, cover.5 ,cover.6 ) according to the position. In x axis there will be the position and in y axis there will be the value of each coverage for 3,4,5,6.

How can i do it in R ?

user3683485
  • 115
  • 1
  • 8

1 Answers1

0

Here you go.

data <- read.table(text=
"txchrom position aregion  cover.3.  cover.4.  cover.5.  cover.6.
1     Chr1    10000       1 0.9784159 0.9721487 0.5981375 0.9132184
2     Chr1    20000       1 1.0863354 1.1126714 0.5539226 1.1368213
3     Chr1    30000       1 1.2473976 0.8157534 0.5298649 1.1845525
4     Chr1    40000       1 1.2364256 0.7356141 0.6598456 0.8775449
5     Chr1    50000       1 0.6970729 0.4664318 0.3653256 0.5954298
6     Chr1    60000       1 0.6122086 0.5031472 0.2324904 0.6616862
7     Chr1    70000       1 0.7551553 0.6788025 0.4354427 0.6946689
8     Chr1    80000       1 1.0065884 0.9707345 0.8338270 0.9644197
9     Chr1    90000       1 0.6890880 0.6679611 0.4118416 0.8105101
10    Chr1   100000       1 0.6825312 0.6406786 0.3253632 0.7034053",
header=T)

library(ggplot2)
library(reshape2)

m_data <- melt(data, id.vars=c("txchrom","position","aregion"))

p1 <- ggplot(m_data, aes(x=position, y=value,group=variable,
                         colour=variable)) +
  geom_line()
p1

enter image description here

Heroka
  • 12,889
  • 1
  • 28
  • 38