What is morally acceptable? It depends where you live.

In 2013, the Pew Research Global Attitudes Project asked over 40,000 respondents in 40 countries about their opinions on eight topics generally considered to be moral issues:

  • Abortion
  • Divorce
  • Drinking alcohol
  • Extramarital affair
  • Gambling
  • Homosexuality
  • Sex between unmarried adults, and
  • Use of contraceptives

Respondents indicated their sentiment about each issue by choosing one of the following responses:

  • Morally unacceptable
  • Morally acceptable
  • Not a moral issue
  • Depends on the situation, or
  • Refused to answer

Unsurprisingly, there was a great deal of variation in responses across countries and topics. The data suggest that Pakistan and Ghana are the most conservative countries in their attitudes toward the eight issues covered, while France and Germany the most liberal. Around the world, there is general agreement that using contraceptives is morally acceptable and even more consensus that extramarital affairs are morally unacceptable. In some countries, it appears that the most controversial or uncomfortable topic was that of homosexuality, with up to 11% of respondents in India and Pakistan refusing to even answer the question of whether homosexuality is morally acceptable or not.

For more interesting insights, explore the visualization below. [Confession: I like radar charts. While some may disagree, I find them morally acceptable and quite useful, although they require a bit of getting used to. I decided to show some aspects of the data using a radar chart because it effectively presents multivariate data and provides quick visual cues for commonalities and outliers. Select a couple of countries and watch the difference in shapes to draw your conclusions.]

ANDRES ALVAREZ - Very good investigation and very good showing

pgupta - Hi George, this is an awesome viz. I had a question – did you have to pre-compute the x,y coords that I see in the underlying data? I guess I can do that, based on the known slope of the line corresponding to the “point”. But just wanted to check in with you.

Country point Country Question Value X Y
France 0 France Having an extramarital affair 47 21 21.103601885
France 1 France Sex between unmarried adults 6 0 3.81
France 2 France Having an abortion 14 -6 6.286179285

Thank you.

George Gorczynski - Hi – Thanks for your comment and a question, pgupta. Yes, I calculated the X and Y of each point in the data source. However, these calculations could also be carried out in Tableau.

10 Questions for Tableau Zen Master Kelly Martin - […] Gorczynski’s Morally Acceptable – I’m usually annoyed by radar charts, but this is […]

Angela - Hi may I ask how do you create the background circles to show the percentages?

Back to top|Contact me

The Militarization of Police in the US

At the end of August, US president Barack Obama ordered a review of federal programs that enable local and state law enforcement agencies to receive or purchase military equipment. This decision was prompted by the unsettling images of heavily armed police officers during clashes that followed the recent fatal shooting of a black teenager in Ferguson, Missouri.

Within one such federal program, the “1033 program” initiated in 1991, over $5.1 billion in military hardware was transferred to date to 8000 local and state law enforcement agencies in the United States.  Since 2006, police have received tens of thousands of pieces of surplus military equipment from the government worth almost $2 billion. This includes, 80,000 rifles, 50 fixed wing airplanes, over 400 helicopters, 350 boats, 350 armored vehicles, among them dozens of mine resistant vehicles, and close to 20,000 pieces of night vision and infrared gear. As of 2014, 184 police departments had been suspended from the program for failure to comply with guidelines and missing weapons ranging from assault rifles to armored Humvees.

In May, The New York Times requested and received a database of military equipment transfers (2006-2014) from the Pentagon. I obtained this raw data from the GitHub account where the Times graciously posted it. I was inspired by the work of NYT graphics department on this topic but the visualization below represents my interpretation of the data. I presented the dollar value and quantities of the military gear transferred to individual states and counties. I also combined it with population statistics to normalize the acquisition numbers and get a better idea of the size of per capita transfers. Finally, I looked at the relationship between crime statistics and the size of transfers to individual states, and I investigated crime and police homicide trends over the last decade.

Douglas Galloway - Great Viz ! very relevant and telling of what may or may not be a really dangerous epidemic. Is the 210M is enough to support a small war.

George Gorczynski - Thank you for your comment, Douglas. Agreed, the numbers are staggering. It would be interesting to know how this equipment is being utilized (i.e. 79 helicopters, 8 airplanes and a mine resistant vehicle in Brevard County alone). In some cases the acquisitions may be justified and we all want the police force to be adequately equipped and protected. But the trend is certainly troubling.

AOK ManRay - I’m all about constantly examining policies and their effectiveness, and correcting when we see waste or no improvement or–worst of all–making things worse through unintended consequences. However, I wanted to highlight a major fallacy that you hint at here. By highlighting the areas that have high militarization and low crime, you are suggesting that this is inappropriate. But how do you know that there is no cause and effect here? I have no idea whether that’s true or not, I just feel that it’s something to be considered. If that were true, then it would be more worthwhile to highlight those who have high military spending and high crime–why has the system failed them? Or have they only more recently received equipment? Or maybe it was even higher before? I have no answers to these questions, just wanted to highlight the challenges with correlations…

Beautiful viz, btw! Very clear, concise and easy to read. Thanks for sharing!

George Gorczynski - You raised a very good point, thanks. More granular (state/county level) analysis of crime rate trends would be valuable.

Back to top|Contact me

Random Walk from Processing to Tableau

For another submission to Viz as Art contest at Tableau, I wanted to create something involving randomness and random walk specifically. But I found that the classic random walk algorithm creates results that are, well…too random, as opposed to the organic, botanical shapes I was looking for. Luckily, someone has already thought of developing a “Random Walk with Transition Probabilities that Depend on Direction of Motion”. It sounds nerdy, but that is just the recipe that Mother Nature uses to build branches on a blueberry bush, dandelion’s see head or the maple tree outside my window.  In particular, a particle always moves forward and changes direction or stays the course dependent on a given probability. One of the chapters in Clifford Pickover’s book “Computers, Pattern, Chaos and Beauty” describes this in more detail.

As with Lorenz Attractor visualization, I wrote a program in Processing to generate the points and export them to a text file. Below is a complete listing of the code:

PrintWriter textFile;
//number of branches
int branchNum = 200;
//scale factor for angle theta
float delTheta = .9;
//scale factor for radius
float delRadius = 0.05;
//probability of transmission
float pt = 0.2;
//number of steps
int stepNum = 150;
//direction angle
float Theta = 0;

void setup(){
size(1000,1000);
background(0);
 
//initialize output text file
//textFile = createWriter("txtfiles/points.txt");
 
for (int branch = 0; branch < branchNum; branch++) {
//set initial conditions for each branch
float x0 = width/2;
float y0 = height/2;
float radius = 1;
 
float res = 0;
float dir = 1;
float lastDir = 1;
float thresh = 0;
strokeWeight(0);
stroke(0);
fill(random(1,255), random(1,255), random(1,255));
//stroke(random(1,255), random(1,255), random(1,255));
 
for (int step = 0; step < stepNum; step++) {
if (step == 0) {
res = random(0,1);
if (res > 0.5) {
dir=1;
} else {
dir=-1;
}
res = res * dir;
Theta = Theta + (res * delTheta);
radius = radius + delRadius;
float x = radius * cos(Theta) + x0;
float y = radius * sin(Theta) + y0;
line(x0, y0, x, y);
x0 = x;
y0 = y;
lastDir = dir; 
} else {
if(lastDir == -1) {
thresh = pt;
} else {
thresh = 1 - pt; 
}
 
res = random(0,1);
if (res > thresh) {
dir = 1;
} else {
dir = -1; 
}
res = res * dir;
Theta = Theta + (res * delTheta);
radius = radius + delRadius;
float x = radius * cos(Theta) + x0;
float y = radius * sin(Theta) + y0;
line(x0, y0, x, y);
ellipse(x,y,10,10);
x0 = x;
y0 = y;
lastDir = dir; 
 
//save output to text file
//textFile.println(branch + "," + x + "," + y);
//textFile.flush();
//exit(); 
         }
      } 
   }
} 

Just by changing one or two parameters, one can create an infinite number of patterns, some more organic looking than others. Here are sample outputs from Processing:

random walk in Processing

I imported the points into Tableau and played with different shapes, sizes an colours to achieve the best look. In the end, I settled for a basic grey circle with white outline. At first the monochrome chart was an uninteresting jumble of random points but after I added Branch field (unique branch number) to the Level of Detail, all tendrils got nicely separated revealing their organic structure.

Back to top|Contact me

Lorenz Attractor – There is Chaos in Tableau!

Inspired by the work of Noah Salvaterra and his beautiful Tableau visualizations of fractals and L-Systems, I made this visual of the Lorenz Strange Attractor. Edward Lorenz, a meteorologist and mathematician,  developed a set of equations to model atmospheric convection. When plotted in 3-dimensional space, the equations generate a beautiful pattern. If you want to know more, here is a nice introduction to Chaos Theory.

How did I make the plot in Tableau? I used Processing to generate the points (see code below) but this could could as easily be done in Excel.

PrintWriter textFile;

//set parameters
float h=0.008;
float a=10;
float b=28;
float c=8/3;

//set initial conditions
float x=0;
float y=10;
float z=10;


void setup() {
  //initialize output text file
  textFile = createWriter("txtfiles/points.txt");
  for(int i=0;i<10000;i++) {
    x+=h*a*(y-x);
    y+=h*(x*(b-z)-y);
    z+=h*(x*y-c*z);
    //print output to console (optional)
    println(x + "," + y + "," + z);
    //save output to text file
    textFile.println(x + "," + y + "," + z);
    textFile.flush();
    exit(); 
  }
}  

I then imported the text file into Tableau, used X,Y coordinates to make a scatter plot, and applied Z coordinate to Size to simulate 3D.

pgupta - Hi George, I looked at your awezome viz, one Q – how do you get the right circles to come out “on top”. There is a line going into the top circle, how does that line appear to be on top of the underlying circles in the background. How would tableau know based on just x,y,size data which one to recede into the background. Thanks and congrats on the viz! It really stopped me in my tracks.

George Gorczynski - Thanks for your comment, pgupta. Although the viz is obviously 2-D, there is a Z component in the data file. Dropping it on the Detail shelf forces Tableau to draw points “closer to you” (larger Z) first.

Back to top|Contact me

Photo Art in Tableau

Do you know what pointillism is? It’s a technique of painting with small distinct dots to create an image. And you can do this with Tableau! Well, sort of.
I made this series of pointillistic representations of well known photographs and paintings for Tableau’s Viz As Art contest. Be sure to click on the “photoart” tab to view my collection of 10 images, as well at the “revolution” tab.

I used Processing to extract each pixel’s coordinate and colour value, convert RGB colour values to greyscale and output the table to a text file. The Processing code is listed below. Note that I am yet to find a way to properly highlight Processing syntax in WordPress, let me know if you use a plugin that understands Processing. If you are wondering about the RGB to grayscale conversion step, read this Wikipedia article.

PImage photo;
PrintWriter textFile;
//enter name of file you want to process (no extension)
String file = "Obama";

void setup() {
  //load image
 photo = loadImage(file + ".png");
  //initialize output text file
 textFile = createWriter("txtfiles/" + file + ".txt");
    for (int column = 0; column < photo.width; column++) {
      for (int row = 0; row < photo.height; row++) {
      //extract pixel's colour value
      color c = photo.pixels[row*photo.width+column];
 //convert RGB values to grayscale
      int g = round(red(c)*0.2126+green(c)*0.7152+blue(c)*0.0722);
 //print output to console (optional)
 println(column + "," + row + "," + g);
 //save output to text file
      textFile.println(column + "," + row + "," + g);
      textFile.flush();
      exit();
  }
 }
}

I imported the resulting text files to Tableau and plotted them as scatterplots, varying the symbol Size by the reverse of grayscale values (I wanted larger symbols for darker areas or lower grayscale values). I also binned the grayscale values and applied a 4 colour palette to points.

This technique works best with clean, contrasty images with easily discernible shapes. You may try to experiment with different sizes of original images, but I find that lower resolution gives better results, so before conversion to text I resampled all my source images to 100×100 pixel size. That results in a viz that has abstract quality, as opposed to being a close replication of the original.

Back to top|Contact me