[R] alternate tick labels and tick marks with lattice xyplot
Leah Marian
lmpreus at gmail.com
Wed Jul 18 20:02:49 CEST 2012
Yes,
I would be interested in both the ggplot2 and lattice ways of doing
this. Unfortunately, I am not interested in creating a panel for each
chromosome. Actually, I would like to create a Manhattan plot using
xyplot. Thus I would need to alternate tick marks and tick labels.
Thanks!
On Mon, Jul 16, 2012 at 12:11 PM, John Kane <jrkrideau at inbox.com> wrote:
>
> I have not seen any response yet so I thought I would reply.
>
> No idea of how to do this in lattice but an approximation of it can be done in ggplot2. I am trying to learn ggplot2 and it was a handy exercise. I still have not figured out how to get the extra line on the x-axis, hence the lines in the graph body instead
>
> Example:
> ##++++++++++++++++++++++++++++++++++++++++++++++++++++++++++###
>
> library(ggplot2)
> data <- structure(list(Chromosome = c(1, 1, 1, 1, 2, 2, 2, 2, 3, 3, 3,
> 3), BasePair = c(1, 2, 3, 4, 1, 2, 3, 4, 1, 2, 3, 4), Pvalue = c(0.819178665755317,
> 0.462827404495329, 0.44360001408495, 0.871020796708763, 0.404167180880904,
> 0.115009917411953, 0.51048326632008, 0.292681957129389, 0.839718346949667,
> 0.586992112919688, 0.29609977430664, 0.873988818377256), indice = 1:12,
> group = c("Group 1", "Group 2", "Group 1", "Group 1", "Group 1",
> "Group 1", "Group 2", "Group 1", "Group 2", "Group 1", "Group 2",
> "Group 2")), .Names = c("Chromosome", "BasePair", "Pvalue",
> "indice", "group"), row.names = c(NA, -12L), class = "data.frame")
>
> library(ggplot2)
>
> p <- ggplot(data, aes(indice, -log10(Pvalue))) + geom_line() +
> opts(legend.position = "none") +
> scale_y_continuous(expression(paste(-log[10], "p-value"))) +
> scale_x_continuous("Chromosome", breaks=c(2.5, 6.5 ,10.5), labels=c("1", "2","3")) +
> geom_segment(aes(x = 4, y = 0.01, xend = 9, yend = 0.01, colour = group)) +
> opts(title = "Results") + facet_grid(. ~ group)
> p
>
> ##===========================================================##
> John Kane
> Kingston ON Canada
>
>
> > -----Original Message-----
> > From: lmpreus at gmail.com
> > Sent: Fri, 13 Jul 2012 15:33:43 -0400
> > To: r-help at r-project.org
> > Subject: [R] alternate tick labels and tick marks with lattice xyplot
> >
> > Hi,
> >
> > I would like to use xyplot to create a figure. Unfortunately, I cannot
> > find
> > documentation in xyplot to specify alternating the x-axis tick labels
> > with
> > the x-axis tick marks. I can do this with the regular R plot function as
> > follows.
> >
> >
> > #A small version of my data looks like this
> > data<-data.frame(matrix(ncol=3,nrow=12))
> > data[,1]<-rep(c(1,2,3),c(4,4,4))
> > data[,2]<-rep(c(1,2,3,4),3)
> > data[,3]<-runif(12,0,1)
> > names(data)<-c("Chromosome", "BasePair", "Pvalue")
> > #using R's plot function, I would place the the chromosome label between
> > the
> > #tick marks as follows:
> > v1<-c(4,8)
> > v2<-c(2,6,10)
> > data$indice<-seq(1:12)
> > plot(data$indice, -log10(data$Pvalue), type="l", xaxt="n", main="Result",
> > xlab="Chromosome", ylab=expression(paste(-log[10]," p-value")))
> > axis(1, v1,labels=FALSE )
> > axis(1, v2, seq(1:3), tick=FALSE, cex.axis=.6)
> >
> > Can this be done with lattice xyplot?
> >
> >
> > --
> > Leah Preus
> > Biostatistician
> > Roswell Park Cancer Institute
> >
> > [[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.
>
> ____________________________________________________________
> GET FREE SMILEYS FOR YOUR IM & EMAIL - Learn more at http://www.inbox.com/smileys
> Works with AIM®, MSN® Messenger, Yahoo!® Messenger, ICQ®, Google Talk™ and most webmails
>
>
--
Leah Preus
Biostatistician
Roswell Park Cancer Institute
More information about the R-help
mailing list