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:> x2chr 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]]
Hi, ggplot2 can also split the graphs in different panels, dread.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. >
On Wed, Nov 18, 2009 at 4:14 AM, Tim Smith <tim_smith_666 at yahoo.com> wrote:> 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.You could do it with library(latticeExtra) segplot(meth ~ start1 + end1 | factor(chr), bar, type = "g") but as Baptiste said, ggplot2 can do conditioning just as well. -Deepayan> 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. >