Question: Plotting matrix of values around specific genomic position
0
gravatar for rbronste
11 months ago by
rbronste360
rbronste360 wrote:

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.

matrix data.frame ggplot2 R • 223 views
ADD COMMENTlink modified 11 months ago by zx87549.7k • written 11 months ago by rbronste360
1

Convert wide-to-long then plot.

ADD REPLYlink modified 11 months ago • written 11 months ago by zx87549.7k
1
gravatar for zx8754
11 months ago by
zx87549.7k
London
zx87549.7k wrote:

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 COMMENTlink modified 11 months ago • written 11 months ago by zx87549.7k
Please log in to add an answer.

Help
Access

Use of this site constitutes acceptance of our User Agreement and Privacy Policy.
Powered by Biostar version 2.3.0
Traffic: 1949 users visited in the last hour