[R] Add another set of labels in a plot for X axis

Gabor Grothendieck ggrothendieck at gmail.com
Sun Nov 11 00:41:16 CET 2007


Try this:

axis(1, 1:22, paste(xaxislabels_1, xaxislabels_2, sep = "\n"), tcl = .3)

On Nov 10, 2007 6:27 PM, Felipe <felipenaranja at gmail.com> wrote:
> I have a protein sequence alignement and for each position of the
> alignement, I want to plot two values (one per sequence). Alignements look
> like this:
>
> MVAFKGVWTQAFWKAVTAEFL
> --------MCSISRKMAAEFI
>
> So, data for the plot would be something like this
>
>
> Prot 1 values:         1 5 2 7 4 3 5 6 8 2 2 7 6 4 2 8 5 8 2 3 7 3
> Prot 2 values:                         1 8 5 0 5 3 4   1 2 2 3 7 0
>
> Aligned Prot 1 seq:    M V A F K G V W T Q A F W K A T V T A E F L
> Aligned Prot 2 seq:    - - - - - - - - M C S I S R K - M A A E F I
>
> Gabor Grothendieck gently helped me (thank you Gabor) so now I can plot the
> two time series, handle gaps (the '-' in the second sequence aligned) and
> change the values in X axis for the values of the first sequence. This can
> be achieved by running this code:
>
> x<-data.frame
> (a=c(1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20,21,22),b=c(1,5,2,7,4,3,5,6,8,2,2,7,6,4,2,8,5,8,2,3,7,3))
> y1<-data.frame(a=c(9,10,11,12,13,14,15),b=c(1,8,5,0,5,3,4))
> y2<-data.frame(a=c(17,18,19,20,21,22),b=c(1,2,2,3,7,0))
> xts <- ts(x$b,start=x$a[1])
> y1ts <- ts(y1$b,start=y1$a[1])
> y2ts <- ts(y2$b,start=y2$a[1])
> xaxislabels_1 <-
> c('M','V','A','F','K','G','V','W','T','Q','A','F','W','K','A','T','V','T','A','E','F','L')
> xaxislabels_2 <-
> c('-','-','-','-','-','-','-','-','M','C','S','I','S','R','K','-','M','A','A','E','F','I')
> ts.plot(xts,y1ts,y2ts,col=c("red","blue","blue"), gpars = list(axes =
> FALSE))
> axis(2)
> axis(1, at=1:22, labels=xaxislabels_1)
>
> Now, how can I add the second sequence values in X axis just below the
> values given in axis(1, at=1:22, labels=xaxislabels_1)?
>
> Thanks in advance.
>
> --
> Felipe
>
>        [[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.
>



More information about the R-help mailing list