# [R] Recurrence plots in R using different colours

Jim Lemon drjimlemon at gmail.com
Thu Oct 12 22:56:10 CEST 2017

```Hi Lisa,
I'm not sure exactly what sort of plot you want, but this may help:

rcol<-matrix(c(1,0,3,1,0,4,0,0,1,0,5,6),ncol=4,byrow=TRUE)
# replace zeros with NAs as there is no numeric color for zero
rcol[rcol==0]<-NA
library(plotrix)
color2D.matplot(rcol,cellcolors=rcol,yat=1:3)

Jim

On Fri, Oct 13, 2017 at 12:18 AM,  <l.handke at tu-braunschweig.de> wrote:
> Hello,
>
> I am an absolutely beginner with regards to R, so forgive me for my
> potentially very stupid questions.
>
> I have been attempting to create recurrence plots using R. The data I am
> using is based on a mutually exclusive and exhaustive coding scheme with
> over 40 individual codes which can be assigned to 6 higher order categories.
> When I carry out the usual rqa command, my plot is pretty much black - no
> surprises there really considering the exhaustive nature of my coding scheme
> and the fact that there are only 6 different categories.
>
> What i would like to do is colour-code my categories in order to arrive at a
> plot that shows the colour of the reccurence of the specific category.
> Eventually that would mean a plot with six different colours (next to white,
> which means no recurrence), rather than the plain black and white plot which
> does not reflect the nature of the recurrence. I hope that my explanation is
> clear enough.
>
> My procedure up until now has been:
>
> 1) perform a recurrence quantification analysis:
>
> testplot <- rqa(time.series = test\$Code, embedding.dim = 1, time.lag = 1,
>
>                radius = 0.1,lmin =2, vmin =2, distanceToBorder = 2, save.RM
> = TRUE, do.plot = TRUE)
>
>
>
> This plot is based on a TRUE FALSE sparse matrix.
>
> 2) Accordingly the next step was to transform this TRUE FALSE matrix to one
> that contains the values for the codes for TRUE and 0 for false:
>
> RP1 <- testplot\$recurrence.matrix
> RP2 <- as.matrix(RP1)*1
> TS <- test\$Code
>
> for (i in seq(1,dim(RP2)[1])) {
>   for (j in seq(1,dim(RP2)[1])) {
>     if (RP2[i,j] == 1) {
>       RP2[i,j] <- TS[i]
>     }
>   }
> }
>
> This results in a matrix of this type:
>
> 1    0    3    1
> 0    4    0    0
> 1    0    5    6
>
>
>
> Now I am missing step 3 --> how can plot this matrix by previously assigning
> different colours to the numbers?
>
>
> Best, Lisa
>
>
>
>
>
> --
>
> M.Sc. Lisa Handke
>
> Technische Universität Braunschweig
>
> Institut für Psychologie
>
> Lehrstuhl für Arbeits-, Organisations- und Sozialpsychologie
>
> Spielmannstrasse 19, Raum 103
>
> D-38106 Braunschweig
>
>
>
> Phone: +49 (0)531-391-2539
>
> Fax:   +49 (0)531-391-8173
>
> Mail:   <mailto:l.handke at tu-braunschweig.de> l.handke at tu-braunschweig.de
>
>  <http://www.tu-braunschweig.de/psychologie/abt/aos>
> www.tu-braunschweig.de/psychologie/abt/aos
>
>
>
>
>         [[alternative HTML version deleted]]
>
>
> ______________________________________________
> R-help at r-project.org mailing list -- To UNSUBSCRIBE and more, see
> https://stat.ethz.ch/mailman/listinfo/r-help