R
ggplot2

例のアレ

More than 3 years have passed since last update.
library(ggplot2)
ggplot(data.frame(x = c(-1, 1)), aes(x)) +
  stat_function(aes(ymin=..y.., ymax=1), fun = function(x) ifelse(x<0, sqrt(10/9-x^2), NA), geom="ribbon", fill="#FFD700", n=1001) +
  stat_function(aes(ymax=..y.., ymin=-1), fun = function(x) ifelse(x>0, -sqrt(10/9-x^2), NA), geom="ribbon", fill="gray50", n=1001) +
  geom_ribbon(aes(ymin=-1, ymax=1), data.frame(x = seq(-1/3, 1/3, len=2)), fill="black") +
  stat_function(aes(ymin = 2/3, ymax = ..y..), fun = function(x) sqrt((1/3)^2-(x-2/3)^2)+2/3, geom="ribbon", fill="red", n=1001) +
  stat_function(aes(ymax = 2/3, ymin = ..y..), fun = function(x) -sqrt((1/3)^2-(x-2/3)^2)+2/3, geom="ribbon", fill="red", n=1001) +
  xlim(-1, 1) + ylim(-1, 1) +
  coord_equal() +
  theme_bw()
ggplot(data.frame(x = c(-1, 1)), aes(x)) +
  geom_ribbon(aes(ymin=-1, ymax=1), fill="black") +
  stat_function(aes(ymin=..y.., ymax=1), fun = function(x) ifelse(x<0, sqrt(10/9-x^2), NA), geom="ribbon", fill="#FFD700", n=1001) +
  stat_function(aes(ymax=..y.., ymin=-1), fun = function(x) ifelse(x>0, -sqrt(10/9-x^2), NA), geom="ribbon", fill="gray50", n=1001) +
  geom_ribbon(aes(ymin=-1, ymax=1), data.frame(x = seq(-1/3, 1/3, len=2)), fill="white") +
  stat_function(aes(ymin = 2/3, ymax = ..y..), fun = function(x) sqrt((1/3)^2-(x-2/3)^2)+2/3, geom="ribbon", fill="red", n=1001) +
  stat_function(aes(ymax = 2/3, ymin = ..y..), fun = function(x) -sqrt((1/3)^2-(x-2/3)^2)+2/3, geom="ribbon", fill="red", n=1001) +
  xlim(-1, 1) + ylim(-1, 1) +
  coord_equal() +
  theme_minimal() + theme(panel.grid = element_blank())