5.3 Dolphins-DT

Dolphins DT right

R Figure

Code
x <- c(0,0,0,0,100,500)
y <- c(0,200,400,500,500,500)

h <- 500
w <- 500

grid.step <- 100

plot( c(0,w), c(0,h),  
     xaxs = "i",yaxs = "i",
     xaxt = 'n', yaxt = 'n',
     type = "n",
     xlab = "Negatives", ylab = "Positives")
     
axis(2,y,labels=c('','p1,p3','p4-5','p1','',''))
axis(1,x,labels=c('','','','','n5','n1-4'))

gx <- grid.step
while (gx <= w) {
  abline(v = gx, col="gray", lty="dotted")
  gx <- gx + grid.step
}
gy <- grid.step
while (gy <= h) {
  abline(h = gy, col="gray", lty="dotted")
  gy <- gy + grid.step
}

text( (x[1]+x[6])/2+10, (y[1]+y[6])/2-10, "A")
text( (x[1]+x[5])/2+10, (y[1]+y[5])/2-10, "B")
text( (x[5]+x[6])/2, y[6]-15, "C")
text( x[2]+10, (y[1]+y[2])/2, "D")
text( (x[3]+x[5])/2+10, (y[3]+y[5])/2-10, "E")
text( x[3]+10, (y[2]+y[3])/2, "F")
text( (x[4]+x[5])/2, y[5]-15, "G")
text( x[4]+10, (y[3]+y[4])/2, "H")

arrows( (x[1]+x[6])/2-10, (y[1]+y[6])/2+10, x[5]+10, y[5]-10, code=2, length=0.1, label="`Gills'" )
Warning in arrows((x[1] + x[6])/2 - 10, (y[1] + y[6])/2 + 10, x[5] + 10, :
"label" is not a graphical parameter
Code
arrows( (x[1]+x[5])/2-10, (y[1]+y[5])/2+10, x[3]+10, y[3]-10, code=2, length=0.1 )
arrows( (x[3]+x[5])/2-10, (y[3]+y[5])/2+10, x[4]+10, y[4]-10, code=2, length=0.1 )

lines( x, y, lwd=5, type='o',col='red')

segments(x[1],y[1],x[6],y[6],lty=3,col="red")
segments(x[1],y[1],x[5],y[5],lty=3,col="red")
segments(x[3],y[3],x[5],y[5],lty=3,col="red")

Python Figure

Code
import matplotlib.pyplot as plt

x = [0, 0, 0, 0, 100, 500]
y = [0, 200, 400, 500, 500, 500]

h = 500
w = 500
grid_step = 100

fig, ax = plt.subplots()
ax.set_xlim(0, w)
(0.0, 500.0)
Code
ax.set_ylim(0, h)
(0.0, 500.0)
Code
ax.set_xticks(x)
ax.set_xticklabels(['', '', '', '', 'n5', 'n1-4'])
ax.set_yticks(y)
ax.set_yticklabels(['', 'p1,p3', 'p4-5', 'p1', '', ''])

gx = grid_step
while gx <= w:
    ax.axvline(x=gx, color='gray', linestyle='dotted')
    gx += grid_step

gy = grid_step
while gy <= h:
    ax.axhline(y=gy, color='gray', linestyle='dotted')
    gy += grid_step

ax.text((x[0] + x[5]) / 2 + 10, (y[0] + y[5]) / 2 - 10, "A")
ax.text((x[0] + x[4]) / 2 + 10, (y[0] + y[4]) / 2 - 10, "B")
ax.text((x[4] + x[5]) / 2, y[5] - 15, "C")
ax.text(x[1] + 10, (y[0] + y[1]) / 2, "D")
ax.text((x[2] + x[4]) / 2 + 10, (y[2] + y[4]) / 2 - 10, "E")
ax.text(x[2] + 10, (y[1] + y[2]) / 2, "F")
ax.text((x[3] + x[4]) / 2, y[4] - 15, "G")
ax.text(x[3] + 10, (y[2] + y[3]) / 2, "H")

ax.annotate('', xy=(x[4] + 10, y[4] - 10), xytext=((x[0] + x[5]) / 2 - 10, (y[0] + y[5]) / 2 + 10),
            arrowprops=dict(arrowstyle='->'))
ax.annotate('', xy=(x[2] + 10, y[2] - 10), xytext=((x[0] + x[4]) / 2 - 10, (y[0] + y[4]) / 2 + 10),
            arrowprops=dict(arrowstyle='->'))
ax.annotate('', xy=(x[3] + 10, y[3] - 10), xytext=((x[2] + x[4]) / 2 - 10, (y[2] + y[4]) / 2 + 10),
            arrowprops=dict(arrowstyle='->'))

ax.plot(x, y, linewidth=5, color='red', marker='o')

ax.plot([x[0], x[5]], [y[0], y[5]], linestyle='dashed', color='red')
ax.plot([x[0], x[4]], [y[0], y[4]], linestyle='dashed', color='red')
ax.plot([x[2], x[4]], [y[2], y[4]], linestyle='dashed', color='red')

ax.set_xlabel("Negatives")
ax.set_ylabel("Positives")

plt.show()

Dolphins DT left

Code
graph TD;
    L2["D: [2+, 0−]"]:::filled
    N1["A: Gills"]
    N2["B: Length"]
    N3["E: Teeth"]
    L1["C: [0+, 4−]"]:::filled
    L3["F: [2+, 0−]"]:::filled
    L4["G: [0+, 1−]"]:::filled
    L5["H: [1+, 0−]"]:::filled

    N1 -- "=no" --> N2
    N1 -- "=yes" --> L1
    N2 -- "=5" --> L3
    N2 -- "=3" --> L2
    N2 -- "=4" --> N3
    N3 -- "=few" --> L4
    N3 -- "=many" --> L5

    classDef filled fill:#f0f0f0,stroke:#000,stroke-width:1px;
graph TD;
    L2["D: [2+, 0−]"]:::filled
    N1["A: Gills"]
    N2["B: Length"]
    N3["E: Teeth"]
    L1["C: [0+, 4−]"]:::filled
    L3["F: [2+, 0−]"]:::filled
    L4["G: [0+, 1−]"]:::filled
    L5["H: [1+, 0−]"]:::filled

    N1 -- "=no" --> N2
    N1 -- "=yes" --> L1
    N2 -- "=5" --> L3
    N2 -- "=3" --> L2
    N2 -- "=4" --> N3
    N3 -- "=few" --> L4
    N3 -- "=many" --> L5

    classDef filled fill:#f0f0f0,stroke:#000,stroke-width:1px;