# Comparing maps

Different maps can be compared using the `procrustesMap()` function where one map is compared to another.

## The example map

We’ll read in the H3N2 2004 map as an example map

    library(Racmacs)
    map_file <- system.file("extdata/h3map2004.ace", package = "Racmacs")
    map <- read.acmap(map_file)
    view(map)

## Comparing optimization runs

We can use the `procrustesMap()` function to compare the top 2 optimization runs.

    pc_run12 <- procrustesMap(
      map                            = map,
      comparison_map                 = map,
      optimization_number            = 1,
      comparison_optimization_number = 2
    )

    view(pc_run12)

## Comparing 3D to 2D

We can also compare 3D map solutions to 2D map solutions. Firstly we will create a 3D version of our map with a fresh set of optimizations (choosing only 10 runs here for speed).

    map3d <- optimizeMap(
      map                     = map,
      number_of_dimensions    = 3,
      number_of_optimizations = 10,
      minimum_column_basis    = "none"
    )
    #> Discarding previous optimization runs.
    #> Warning: Number of parallel cores to use for optimization was not specified, so using default of 2. You can set the number of cores to use explicitly by passing it as an argument to the optimizer function, or globally by setting the option 'RacOptimizer.num_cores', e.g. by adding the line `options(RacOptimizer.num_cores = parallel::detectCores())` to the top of your script.
    #> This warning is displayed once every 8 hours.
    #> a
    #> Warning: The following SERA have do not have enough titrations to position in 3 dimensions. Coordinates were still optimized but positions will be unreliable
    #>
    #> 'HK/107/71'
    #> Took 1.85 secs
    #> Warning in optimizeMap(map = map, number_of_dimensions = 3,
    #> number_of_optimizations = 10, : There is some variation (7.7 AU for one point)
    #> in the top runs, this may be an indication that more optimization runs could
    #> help achieve a better optimum. If this still fails to help see ?unstableMaps
    #> for further possible causes.

Now we will run procrustes map on the 3d version and view the result, by default an extra grid is drawn showing the dimensions to which the comparison map was constrained.

    pc_3d2d <- procrustesMap(
      map            = map3d,
      comparison_map = map
    )

    view(pc_3d2d)