Colors in treemap - r

it would be great to clarify how colors are calculated when ploting treemap (I use gvisTreeMap function from R googleVis library).
Documentation is not very informative. What is it meant by "The color value is first recomputed on a scale from minColorValue to maxColorValue"? Usually I use treemap to display sales (size) and sales difference (color). So ideally I would like to color rectangles so that I can distinguish positive from negative growth, which as I understand is not possible at the moment.
What bothers me most right now is that "... colors are valued relative to all other nodes in the graph". Is there any way to fix colors, so that sales difference, say -25 always gets the same color.

If I have understood your problem correctly, I believe the following will solve it:
Let's say your data is percentages, so can go from 0 to 100. Set minColorValue=-100 and maxColorValue=100
(Or if using a different range, just set it so that the min value is the negative of the max value so that the average is 0.)
Then, if you set the colours to, for example, minColor='red' and maxColor='green', this should solve part 1 (negative values will be displayed in red, and positive in green)
Also, it seems that setting maxColor and minColor fixes the average value the colors are calculated from, so that this also solves part 2 (that is, -25 will then always have the same color in the graph)

Color is computed as the average color value of all child nodes of a branch. A branch with no child nodes uses the color value from the DataTable. This color value is then scaled on the minColorValue to maxColorValue scale, and a color is computed between minColor and maxColor based on the scale.
Colors are not relative to other nodes on the graph - the size of the node is relative.

Related

max dot size in R ggplot

I am trying to write a R-Script that saves a series of Maps with Dots on it. For the Map I used ggmap and geom_point for the Dots. There is a map for each day in a certain time range.
The size of the Dots depends on a certain variable, but I have a problem scaling them. I am supposed to create later an animation of all the maps changing the dots' size through time, that means that I need a global scale for the dimension of the dots, spacing from the smallest value (zero) to the biggest value of that variable (the global maximum). In the most maps the biggest value is not reached.
I tried with:
scale_size_area(max_size = max(my_variable))
because scale_size_area allows to plot very tiny dots for the 0 values. I was hoping that the so written code would scale the dots correctly, using the global maximum as maximum size, but it doesn't seem to work. Every map has still a locally biggest dot that has the same size of any biggest dot in every map. Here's an example where two points with different values have the same size:
I hope I could explain my problem. I'd be glad to hear some suggestion.
To set the maximum and minimum values in a scale (size or otherwise), use limits:
scale_size_area(limits = c(NA, max(your_varible))
NA computes the minimum

Fading effect with QCPItemTracer

I have been able to use QCPItemTracer to trace a specific point on my data when plotting. How do I achieve a fade out effect? That is, as the next point is plotted, the last n points fade out slowly. Does Qt provide such a feature?
I'm not familiar with this class of QCustomPlot but it should be easy to implement what you are asking for your self. You just need to keep track of the last n points. When it comes to plotting this is often referred to as oscilloscope-type persistence.
Fade out effect is usually achieved by gradually changing either the alpha channel or the color value of the item you want to affect. The first is relatively easy but requires alpha support (QCustomPlot does support it) and decreases performance of your plotting tool. The second requires you to calculate a gradient starting with the color the point was originally plotted with and going all the way up/down to whatever background color you have selected for your plot. The gradient step can directly be derived from n.
For every n+1 point just iterate through the n points before that
For each of those points reduce the alpha or change the color
I'm presuming that fade out effect you want also needs to be distributed unequally among all points based on their age with point n (the youngest) being the least affected and point 0 (the oldest) being the most affected by the fade out effect like this (from left to right age of a point increase):

Plotting Count (colormap) in R

I have a 200 by 200 matrix in R. Each column represents a future state (1-200), each row represents a current state (1-200). Within the matrix is the likelihood of going from given current state (row) to given future state (column).
I would like to visualize this using a graph, I was suggested using
image()
function in R however the scales are highly incorrect and when I attempt to change them the entire "color map" changes too.
Ideally, id like to use color to demonstrate most likely transition (dark color) and have it gradient through to less likely transition (light color).
Could anybody point me in the fight direction?

Is there a formula to get distinct colors in RGB representation

A color can be represented as mixture of Red,Green and Blue.
Ex: (255,51,153)=pink
Is there an any good formula to get distinct colors by changing one variable?
such as (10x,22x,2x^2). So when x=1,2,3,4,.... It will give separate colors like Red,Green,Cyan,Blue.....etc.
Perhaps you'd be more interested in using HSL/HSV colors. Define the saturation and lightness and adjust the hue to get different colors. Check out the HSL and HSV wiki to learn more. A 15 to 30 degree adjustment of hue will result in a distinctly different color without messing with saturation or lightness.
An example of hsl in CSS is as follows.
<h1 style="color:hsl(0,50%,100%);">HSL Test</h1> //this will be red
The first value at 0 is red and advancing by 120 degrees will bring you to green and another 120 will bring you to blue and the last 120 will bring you back to red since the degree system is based on the 360 degrees of a circle. So 0 and 360 are the same just 60 & 420. The next two values are percentage based from 0% to 100% to define the intensity of that property. They're hard to explain so I made a quick fiddle that demonstrates this.
So to answer your question there is a good formula to adjust color it just depends on how exactly you want to change it. In the RGB world you can make things darker by lowering values uniformly and the opposite by heightening them. You can increase the different color presences by adjusting the individual color values as expected. However if you're trying to cycle the entire color wheel then this is difficult (although entirely possible) using RGB values. The real lesson to take away is that there are a number of ways to define a specific color and with each one different ways to traverse the spectrum. HSL and HSLA are very intuitive for many people since it's values don't really have to be guessed at. Pick a specific hue off the color wheel, Remember ROYGBIV as you imagine a value from 0-359. Define a saturation based on how bold you want the color to be and then a lightness based on how bright. It's far more useful then RGB in the large majority of cases as you'll see in that fiddle. Making a subset of the entire color spectrum with javascript only takes a few lines of code.
There is a similar question here
This javascript library can help you Name the Color Javascript Lib
A Demo of the library

Optimization: minimize painting errors

You are given an m*n grid, where each cell is marked either "b" or "w". You are also given black and white paints. You are allowed to use k strokes, each of any color (black OR white), a stroke is defined as coloring of contiguous uncolored cells from the same row (which means a stroke can not go beyond the length of the row, also if you pick up your brush before the end of the row thats the end of that stroke). The aim is to minimize the number of errors, an error occurs if you paint a cell with wrong color OR a cell remains unpainted. What is the optimal strategy?
Knowing solution for one row problem (what is a minimal number of errors with k strokes on a given BW row) can be used to solve problem.
For each row make list of number of errors for given number strokes k_i = [0, 1, ..., min k needed to cover i-th row]. Now we have n lists (of different sizes). To find in which rows to use 'k' strokes, it is enough to iteratvely pop k elements from begining of list which stroke cover most cells.
So, main task is to solve one row problem, and I'm not sure how :-)
Let C be number of colour changes in a row. Than minimal number of strokes to cover row is a ceil( (C+1)/2 ). That can be done by alternate stroke colour with first stroke to cover whole row and next strokes between most distant change in a last stroke. First stroke has colour of one (or both) end(s).
I think , with similar approach it is possible to find number of errors when there isn't enough strokes to cover whole row. Some ranges of one colour have to be omitted. That is be done by:
starting with colour that is not on a boundary (omitting first stroke),
some strokes are not between most distant change in last stroke, but
between closer changes.
I'm not sure, but it seems like it is enough to find few smallest same colour parts and that is what will stay as an error. Probably it is important how far these parts are from ends.
That is for now ...

Resources