jokergoo / spiralize

Visualize data on spirals
https://jokergoo.github.io/spiralize/
Other
147 stars 13 forks source link

Some questions about using the library #43

Open ogreyesp opened 1 year ago

ogreyesp commented 1 year ago

Hi @jokergoo

I would be interested in using your library for plotting some multivariate longitudinal data. I was wondering the following:

1- Is it possible to create a spiral not by using the Archimedean formula, but the method of two points centers? 2- If a create different spirals, is possible to fill the space between spirals by doing a color interpolation method?

Best regards and thanks

jokergoo commented 1 year ago

Hi, no for the first question. It is only for Archimedean spirals.

Second, I don't know how will you interpolate colors exactly. Normally you need to manually self-define a color interpolation function to generate colors... e.g. to linearly interpolate between white and red:

# a color mapping function which maps values in [0, 1] to [white, red]
col_fun = colorRamp2::colorRamp2(c(0,1), c("white", "red"))
n = 1000
spiral_initialize(xlim = c(0, n))
spiral_track(ylim = c(0, 1))
col = col_fun(1:n/n)
spiral_rect(0:(n-1), 0, 1:n, 1, gp = gpar(fill = col, col = col))
image

or from the other direction:

n = 100
spiral_initialize(xlim = c(0, 1))
spiral_track(ylim = c(0, n))
col = col_fun(1:n/n)
spiral_rect(0, 0:(n-1), 1, 1:n, gp = gpar(fill = col, col = col))
image
ogreyesp commented 1 year ago

Hi @jokergoo

Thanks for your response.

The examples that you give are very useful. However, I´m trying to achieve other kind (more complex) linear interpolation.

Let's take the following example:

4760acc0-f987-4640-a1d4-1a2f17548a73

I'm interested in doing a linear interpolation of the NULL|WHITE spaces between spirals segments, so at the end every NULL space will be filled with a color. To do this, let's plot a horizontal line as an example. The intersection of the line with each border polygon comprising the spiral(s) is computed. Figure shows the final small segments of the line that are used to perform the linear interpolation of the NULL spaces. In the example, each interpolation is delimited by an independent pair of consecutive red points; so in this example there would be 16 interpolation lines.

The colours of a small interpolation segment are calculated by doing a linear interpolation that will always have a WHITE value in the middle. So, let say that a small segment intercepts at LEFT side with a polygon of color BLUE, and at RIGHT side with a polygon of color RED, then the small segment between these two polygons will have colours ranging from BLUE -> WHITE (middle) -> RED.

We can take the same line and rotate it by a small angle until reaching 180 degrees, and repeat the procedure described above in every timestep, so at the end every NULL space between spirals will be filled. I know that this interpolation is far from your library purpose, but maybe you have an idea of how to achieve this without using a very computational geometry expensive approach. I have implemented it in Python, but when I saw your spiralize library (that is amazing) I decided to translate my code to R.

Bets regards

PD: Also, I would like to know how to create several spirals (not tracks) in the same plit. So, each spiral can start at different x-points (global reference).