Message-ID: <de4e29f50911180242m64e47ecdk82fd8adf33bdc9b0@mail.gmail.com>
Date: 2009-11-18T10:42:59Z
From: Baptiste Auguie
Subject: Lattice plot
In-Reply-To: <775688.7210.qm@web57505.mail.re1.yahoo.com>
Hi,
ggplot2 can also split the graphs in different panels,
d=
read.table(textConnection(
"chr start1 end1 meth positive
1 1 10 20 1.5 y
2 2 12 18 -0.7 n
3 3 22 34 2.0 y
4 1 35 70 3.0 y
5 1 120 140 -1.3 n
6 1 180 190 0.2 y
7 2 220 300 0.4 y"), head=T)
library(ggplot2)
ggplot(data=d) + facet_grid(.~chr) +
geom_segment(aes(x=start1, xend=end1, y=meth, yend=meth))
HTH,
baptiste
2009/11/17 Tim Smith <tim_smith_666 at yahoo.com>:
> Hi,
>
> I was trying to get a graph in lattice with the following data frame (7 rows, 5 cols):
> chr start1 end1 meth positive
> 1 ? 1 ? ? 10 ? 20 ?1.5 ? ? ? ?y
> 2 ? 2 ? ? 12 ? 18 -0.7 ? ? ? ?n
> 3 ? 3 ? ? 22 ? 34 ?2.0 ? ? ? ?y
> 4 ? 1 ? ? 35 ? 70 ?3.0 ? ? ? ?y
> 5 ? 1 ? ?120 ?140 -1.3 ? ? ? ?n
> 6 ? 1 ? ?180 ?190 ?0.2 ? ? ? ?y
> 7 ? 2 ? ?220 ?300 ?0.4 ? ? ? ?y
> I wanted the panels to be organized by 'chr' - which is ok. Further, I wanted the lines to be discontinuous. For example, in the first row, the x co-ordinate starts with a value of 10 (2nd column) and ends with a value of 20 (3rd column). The corresponding y value for this range of x values is 1.5 (4th column). Similarly, for the same panel (i.e chr=1), the fourth row would have x co-ordinate range from 35 to 70 with a y co-ordinate of 3.
> If it were only one panel, a similar result could be achieved for the data x2:
>> x2
> ?chr start1 end1 meth positive
> 1 ? 1 ? ? 10 ? 20 ?1.5 ? ? ? ?y
> 4 ? 1 ? ? 35 ? 70 ?3.0 ? ? ? ?y
> 5 ? 1 ? ?120 ?140 -1.3 ? ? ? ?n
> 6 ? 1 ? ?180 ?190 ?0.2 ? ? ? ?y
>
>
> ## Code courtesy of BAPTISTE AUGUIE
> library(ggplot2)
> ggplot(data=x2) +
> ?geom_segment(aes(x=start1, xend=end1, y=meth, yend=meth))
> - Can I get lattice to do a similar graph for the panels?
> thanks!
>
>
>
> ? ? ? ?[[alternative HTML version deleted]]
>
> ______________________________________________
> R-help at r-project.org mailing list
> https://stat.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
> and provide commented, minimal, self-contained, reproducible code.
>