0

Some years ago this destiny plots were posted. Now i need to create similar sketches, does anyone know how these were created? and what technology would be the best to make something similar?

enter image description here

This graph was originally posted here...

How to use 'facet' to create multiple density plot in GGPLOT

Thanks!

Rui Barradas
  • 70,273
  • 8
  • 34
  • 66

2 Answers2

0

You can use ggplot facets

library("tidyverse")
data = iris %>% gather(key, value, -Species)
data %>% 
   ggplot(aes(x = value, color = Species)) + 
   geom_density() + 
   facet_wrap(key ~ .)
penguin
  • 1,267
  • 14
  • 27
0

There is this matplotlib method in python xkcd() which is intended to give plots that sckechy look. It will give that kind of handmade look to any of your matplotlib plots.

I am not sure wether you asked for this, but I felt creative anyways:

# Load libraries
import numpy as np
import matplotlib.pyplot as plt
import scipy.stats as stats

# Set style and an auxiliar list
plt.style.use('bmh')
figs = []

# Initialise figure and let no space between subplots 
f = plt.figure(figsize = (15,15))
f.subplots_adjust(hspace=0, wspace=0)

# Set the main plot axis labels as text boxes
f.text(0.5, 0.04, r'log2(u)', ha='center', va='center', fontsize=50, color = 'firebrick')
f.text(0.06, 0.5, 'Density', ha='center', va='center', rotation='vertical', fontsize=50, color = 'firebrick')

#Add some magic
plt.xkcd(scale=5, length=800)

# For each plot
for i in range(4):

    plt.subplot(2,2,i+1)
    # Remove internal axis labels
    if i in [0,1]:
        plt.xticks([], [])
    if i in [1,3]:
        plt.yticks([], [])    

    # Set figure captions   
    difs = [r'$W_c - W_n$', r'$X_c - X_n$', r'$Y_c - Y_n$',r'$Z_c - Z_n$']    
    plt.text(0,0,difs[i], fontsize=30, ha = 'center',bbox = dict(facecolor='white', alpha=0.6, edgecolor='red'))

    # generate a couple of gaussians to plot with random mu and sigma
    x = np.linspace(-5,5, 100)
    sigma = (np.random.rand()+0.5)
    mu1 = np.random.choice([-2,-1,0,1,2])
    mu2 = mu1
    while mu2 == mu1:
        mu1 = np.random.choice([-2,-1,0,1,2])
    x1 = stats.norm(mu1,sigma).pdf(x)
    x2 = stats.norm(mu2,sigma).pdf(x)

    # We generate the fill plots 
    a = plt.fill(x, x1, alpha = 0.3,label='C')
    b = plt.fill(x, x2, alpha = 0.3,label='N', color = 'coral')
    plt.xlim(-6,6)
    #get the figures to use them for the legend
    figs.extend([a,b])


# Set the main legend
L=f.legend(figs[0:2],loc='upper center',
          ncol=2, fancybox=True, shadow=True, fontsize = 40)

L.get_texts()[0].set_text('CANCER (c)')
L.get_texts()[1].set_text('NORMAL (n)')

plt.show()

enter image description here

TitoOrt
  • 1,265
  • 1
  • 11
  • 13