simple question

6 views
Skip to first unread message

Bogdan Tanasa

unread,
Feb 10, 2012, 4:51:05 PM2/10/12
to ggplot2
Dear all,

I am very new to ggplot2, and I would like to plot (in line plots)
every column in a matrix 300*60 in one graph.
Please could you advise if there is a quick way to do it. Thanks very
much,

Bogdan

Dennis Murphy

unread,
Feb 11, 2012, 12:58:21 PM2/11/12
to Bogdan Tanasa, ggplot2
Simple example:

library('ggplot2') # version 0.8.9 loads 'reshape' package, too
m <- matrix(rnorm(25), nrow = 5, dimnames = list(1:5, paste('V', 1:5,
sep = '')))
dm <- melt(m)
str(dm)
'data.frame': 25 obs. of 3 variables:
$ X1 : int 1 2 3 4 5 1 2 3 4 5 ...
$ X2 : Factor w/ 5 levels "V1","V2","V3",..: 1 1 1 1 1 2 2 2 2 2 ...
$ value: num 0.795 1.291 -0.343 -1.092 1.106 ...
ggplot(dm, aes(X1, value, colour = X2)) + geom_point() + geom_path()

If you don't need to distinguish colors (and with 60 columns you may
not), replace colour with group in the last aes() term. The qplot()
version is

qplot(X1, value, data = dm, group = X2, geom = c('point', 'path'))

Adapt to your needs.

HTH,
Dennis

> --
> You received this message because you are subscribed to the ggplot2 mailing list.
> Please provide a reproducible example: http://gist.github.com/270442
>
> To post: email ggp...@googlegroups.com
> To unsubscribe: email ggplot2+u...@googlegroups.com
> More options: http://groups.google.com/group/ggplot2

Bogdan Tanasa

unread,
Feb 12, 2012, 12:32:16 PM2/12/12
to Dennis Murphy, ggp...@googlegroups.com
Dear Denis,

thank you very much for your suggestion: using the "melt" function saves a lot of time. If possible, I would like to add another question.

I am trying to plot some graphs based on chromosome positions : on X axis I do have the chromosome positions 1, 100, 200, 300, etc ...Then I have to plot graphs for every position : for instance there is a graph starting at position 100, and then plotting over other positions ...or a graph starting at position 300, and plotting over other positions ...

In other words, for every graph in the legend I have to assign a specific mark on x axis to denotes where the initial starting point of that graph is : in a similar way >abline(v=100) or >abline(v=300) for a legend with the graphs (graphs 100 and graphs 300).

Any suggestions on how I can do it ? thanks very much,

 Bogdan
Reply all
Reply to author
Forward
0 new messages