acorg / Racmacs

Racmacs R package for performing antigenic cartography
https://acorg.github.io/Racmacs/
GNU Affero General Public License v3.0
20 stars 9 forks source link

How to draw the h3map2004 map(colored)? #130

Closed ZhaoZheLin closed 12 months ago

ZhaoZheLin commented 2 years ago

Hello all,
I saw that the original h3map2004 map was colored by clusters, but when I drew the map, all the points were green, plus the map was different every time I ran it. In addition, I saw your reply to Shaoyuan that the agFill() and srFill() functions can only assign values to the color of a single point. Do you know a way to change colors by clusters like in the map ? I want to redraw the h3map2004 map. Thank you for taking the time to answer my questions!

drserajames commented 2 years ago

There are two parts to this question

  1. How to colour the 2004 map?
  2. Why is it different when rerun?

The first part is simpler - the 2004 is included in the package as an ace file. So you can either optimise that map or apply the plot specifications from that map to the one who have run.

# get data 
map <- read.acmap(paste0(system.file("extdata", package = "Racmacs"), "/h3map2004.ace"))
view(map)

# making a map (only 10 optimisation) & colouring as 2004 map
map2 <- optimizeMap(map, number_of_dimensions = 2, number_of_optimizations = 10)
view(map2)
map3 <- make.acmap(titerTable(map), number_of_dimensions = 2, number_of_optimizations = 10)
map3 <- applyPlotspec(map3, map)
view(map3)

The second part is a bit more complicated. The mds algorithm uses random starting coordinates for the points, different ones for each run. So each run may converge on a different local optimum. Depending on your data and optimisation parameter, you may find that the the map is very similar for most of the optimisation runs. But sometimes, as with the 2004 map, there are differences. Also sometimes there are small differences in the stress, but the maps themselves look very similar. You can use set.seed() before running an optimisation if you want to make sure you always get the same results. Is that sufficient to answer your question?

Kevinhokahey commented 1 year ago

There are two parts to this question

  1. How to colour the 2004 map?
  2. Why is it different when rerun?

The first part is simpler - the 2004 is included in the package as an ace file. So you can either optimise that map or apply the plot specifications from that map to the one who have run.

# get data 
map <- read.acmap(paste0(system.file("extdata", package = "Racmacs"), "/h3map2004.ace"))
view(map)

# making a map (only 10 optimisation) & colouring as 2004 map
map2 <- optimizeMap(map, number_of_dimensions = 2, number_of_optimizations = 10)
view(map2)
map3 <- make.acmap(titerTable(map), number_of_dimensions = 2, number_of_optimizations = 10)
map3 <- applyPlotspec(map3, map)
view(map3)

The second part is a bit more complicated. The mds algorithm uses random starting coordinates for the points, different ones for each run. So each run may converge on a different local optimum. Depending on your data and optimisation parameter, you may find that the the map is very similar for most of the optimisation runs. But sometimes, as with the 2004 map, there are differences. Also sometimes there are small differences in the stress, but the maps themselves look very similar. You can use set.seed() before running an optimisation if you want to make sure you always get the same results. Is that sufficient to answer your question?

Hi Dr. Sera James This is Kevin. Thank you so much for your explanation. I have a similar question as ZhaoZheLin. I think what we would like to know is how to customize the shape, size and color of the dots in the plot. For example, we run the codes on the introduction page from loading titer table to optimizing the map created by the acmap(). The map could be plotted for sure. Unfortunately, I have no clue how to customize the plot from that on. As ZhaoZheLin mentioned, all dots were green. Could you please, if I may, do me a favor to show me the codes? Thank you very much.

judyssister commented 1 year ago

Hi Sarah. Thanks for kind help. Could please let me know that what's the difference between optimizeMap() and make.acmap()?