# Define p values
p <- seq(0, 1, length.out = 200)

# Define the three measures
gini        <- 2 * p * (1 - p)
class_error <- 1 - pmax(p, 1 - p)
entropy     <- ifelse(p == 0 | p == 1, 0,
                      -(p * log(p) + (1 - p) * log(1 - p)))

# Plot
plot(p, gini,
     type = "l", 
     ylim = c(0, 0.75),
     xlab = expression(hat(p)[m1]),
     ylab = "Value",
     main = "Node impurity measures")

lines(p, class_error)
lines(p, entropy)

legend("topright",
       legend = c("Gini index",
                  "Classification error",
                  "Entropy"))