Plotting matrix of values around specific genomic position
1
0
Entering edit mode
2.4 years ago
rbronste ▴ 400

Hi I have a data.frame that looks like the following:

    V1       V2            V3        V4
5022970 196.2992494 191.5615348 186.9297418
5023003 98.0686565  97.03803578 96.12656665
5023061 68.8391627  69.53623005 70.76395006
5023121 96.98746392 97.94463568 98.81860247

The first column is a set of genomic locations and columns extending from V2 to V402 are values I want to plot, now I can do this for two columns (col1 = V1, col2 = V2) as follows:

df %>% ggplot() + 
  geom_point(aes(x = V1, y = V2)) +
  scale_y_continuous(limits=c(0,200)) +   
  xlim(5022800, 5023050) + xlab("Genomic Position") +  
  geom_smooth(aes(x = V1, y = V2), 
              method="loess", span=.22, color = "red", fill = "black") + 
  theme_bw()

However I am not sure how to plot all columns from V2-V402 relative to those specific genomic points. Thanks.

R data.frame matrix ggplot2 • 473 views
ADD COMMENT
1
Entering edit mode

Convert wide-to-long then plot.

ADD REPLY
1
Entering edit mode
2.4 years ago
zx8754 11k

Although not sure how informative this would be with 400 lines in one plot, we could reshape from wide to long, then plot:

library(data.table)
library(ggplot2)

#example data
dt <- fread(text = "    V1       V2            V3        V4
5022970 196.2992494 191.5615348 186.9297418
5023003 98.0686565  97.03803578 96.12656665
5023061 68.8391627  69.53623005 70.76395006
5023121 96.98746392 97.94463568 98.81860247")

#reshape wide-to-long
plotDat <- melt(dt, id.vars = "V1")

#plot
ggplot(plotDat, aes(x = V1, y = value, colour = variable)) +
  geom_point() +
  geom_smooth()
ADD COMMENT

Login before adding your answer.

Traffic: 2197 users visited in the last hour
Help About
FAQ
Access RSS
API
Stats

Use of this site constitutes acceptance of our User Agreement and Privacy Policy.

Powered by the version 2.3.6