add alternative approach from 2013-01
[synclust.git] / R / graphics.R
CommitLineData
ad26cb61
BA
1#' Draw (France or...) map with all sites of colors 'cols'
2#'
3#' @param M Coordinates matrix (in columns)
4#' @param cols Vector of colors for each row of M [default: all black]
5#' @export
6#'
15d1825d
BA
7drawMapWithSites = function(M, cols=rep(1,nrow(M)))
8{
9 xMin = range(M[,1])[1]
10 xMax = range(M[,1])[2]
11 yMin = range(M[,2])[1]
12 yMax = range(M[,2])[2]
13 par(mar=c(2,2,2,2))
14 plot(0,0,xlim=c(xMin,xMax),ylim=c(yMin,yMax),col="white")
15 #plot by color groups (limited to integers)
16 maxColor = max(cols)
17 for (i in 1:maxColor)
18 {
19 indices = (1:nrow(M))[cols==i]
20 if (length(indices) > 0)
21 points(M[indices,1],M[indices,2],col=i,xtitle=NULL)
22 }
23}
24
ad26cb61
BA
25#' Draw neighborhoods graph on top of a country map (or any other map)
26#'
27#' @param M Coordinates matrix (in columns)
28#' @param NI Neighborhoods of M rows (list of integer vectors)
29#' @export
30#'
15d1825d
BA
31drawNeighborhoodGraph = function(M, NI)
32{
33 for (i in 1:length(NI))
34 {
35 for (j in NI[[i]])
36 lines(c(M[i,1],M[j,1]),c(M[i,2],M[j,2]))
37 }
38}
39
ad26cb61
BA
40#' Plot a matrix of curves (in rows)
41#'
42#' @param M Coordinates matrix (in columns)
43#' @param cols Vector of colors for each row of M [default: all black]
44#' @export
45#'
15d1825d
BA
46plotCurves = function(M, cols=rep(1,nrow(M)))
47{
48 n = nrow(M)
49 rg = c(min(M),max(M)) #range for plotting
50 for (i in 1:n)
51 {
52 plot(M[i,],col=cols[i],ylim=rg,type="l")
53 if (i < n) par(new=TRUE)
54 }
55}