CartoDB / turbo-carto

CartoCSS preprocessor
BSD 3-Clause "New" or "Revised" License
28 stars 7 forks source link

style by outliers #32

Open javisantana opened 8 years ago

javisantana commented 8 years ago

outliers based on quartiles are a useful way to see some insighs.

With the clustering methods we have rigth now is not easy to plot those because we don't have a way to bucket things by 1.5 IQR distance.

My proposal is to have something like

marker-fill: ramp([attr], cartocolor(OutLiers1), 'IQR')

this will use a OutLiers1 ramp with 3 values:

color1: IQR color2: between IQR and 1.5_IQR color3: > 1.5_IQR (outliers so the color should be able to say so)

cc @makella @rochoa @saleiva

saleiva commented 8 years ago

I absolutely love this idea. The only thing is that if this shouldn't be an analysis rather than a classification type. Open Question here...

javisantana commented 8 years ago

so @makella how do you see creating a color ramp for this? sounds challenging

it should also change the rendering order probably to show the outliers on top

makella commented 8 years ago

@javisantana i haven't responded because I'm not sure I completely understand what you are talking about. Is there an example or something I can read to get a better understanding?

javisantana commented 8 years ago

@makella let me put an example:

This is a map of a gps track of a car in a racetrack. It tracks the position speed and time => https://team.cartodb.com/u/javi/viz/2dbc6cb0-db18-11e5-9281-0e31c9be1b51/embed_map

Imagine we want to analyze if there is something weird with the speed, the way to do it would be to calculate the quartiles, in this case:

Q1, Q2, Q3 = 13.236655, 17.239033, 21.843311
// speed in meters/s

So IQR Q3 - Q1:

IQR =  21.843311 - 13.23 = 8.613311

We consider an outlier when the speed is less than Q1 - 1.5IQR or greater than Q3 + 1.5IQR:

Q3 + 1.5IQR = 21.843311 + 1.5 * 8.613311 = 34.7632775
Q1 - 1.5IQR = 13.236655 - 1.5 * 8.613311 = 0.3166885000000015

Given this we can style the map doing so we style in red and black outliers

#sensor_log_2013_10_27_12_01 [ vel <= 0.3166885000000015] {
   marker-fill:red;
  marker-width: 9;
}

#sensor_log_2013_10_27_12_01 [ vel >= 34.7632775
] {
   marker-fill: black;
  marker-width: 9;
}

as you can see in the map I shared there are red points. Those points are outliers because the car was stopped.

So what I want is to not have to calculate all of this by hand, just have ramps and clustering methods to show easily those outliers. Obviously the ramp I'm using is pretty bad, it should be a ramp that highlight the outliers but at the same time show the regular features.

makella commented 8 years ago

ok going to take a look at the map you sent and will report back :)

makella commented 8 years ago

@javisantana

So if I understand right,

As far as coloring goes, here's an idea: use a single hue, lower chroma ramp in between two complimentary colors (for highest contrast) on either end.

Here's your map (well, I changed the background just to illustrate better): https://team.cartodb.com/u/mamataakella/viz/5aca877d-e124-418f-b6d4-d46b40dfb773/embed_map

Is this what you are picturing? It's not perfect, but to get the idea.

screen shot 2016-05-19 at 2 18 10 pm

screen shot 2016-05-19 at 2 11 04 pm
javisantana commented 8 years ago

Yes, that's it.

In that case the legend should be more like a boxplot to show the idea of a non linear mapping between colors and clusters but you got the idea

cc @saleiva

javisantana commented 8 years ago

the nice thing here: we could calculate the outliers by zone or the general ones \o/

makella commented 8 years ago

ok, cool! So I guess this means we need some palettes to support this in CartoColors, right? Points, lines, polygons should get tested with styling too.

makella commented 8 years ago

@javisantana so would these ramps be for moran's i also? if we need ramps for this i need to make them so if there are any other examples that i can test, that would be helpful.

javisantana commented 8 years ago

totally

makella commented 8 years ago

just for reference, polygon example for the same idea as above https://team.cartodb.com/u/mamataakella/viz/37f5489a-3933-11e6-a223-0e98b61680bf/embed_map