Skip to content

Instantly share code, notes, and snippets.

@gaolei786
Last active December 10, 2015 04:18
Show Gist options
  • Save gaolei786/1b36e494d614e2b6defa to your computer and use it in GitHub Desktop.
Save gaolei786/1b36e494d614e2b6defa to your computer and use it in GitHub Desktop.
太极图
library(ggplot2)
pi.angle <- seq(0, 2*pi, length = 400)
data1 <- data.frame(x = 60*cos(pi.angle), y = 60 * sin(pi.angle))
x1 <- 60 * cos(seq(-pi/2, pi /2, length = 200))
x2 <- 30 * cos(seq(pi/2, -pi/2, length = 100))
x3 <- 30 * cos(seq(pi/2, pi * 3/2, length = 100))
x <- c(x1, x2, x3)
y1 <- 60 * sin(seq(-pi/2, pi /2, length = 200))
y2 <- 30 + 30 * sin(seq(pi/2, -pi/2, length = 100))
y3 <- -30 + 30 * sin(seq(pi/2, pi * 3/2, length = 100))
y <- c(y1, y2, y3)
data2 <- data.frame(x2 = x, y2 = y)
x <- 10 * cos(pi.angle)
y <- -30 + 10 * sin(pi.angle)
data3 <- data.frame(x3 = x, y3 = y)
x <- 10 * cos(pi.angle)
y <- 30 + 10 * sin(pi.angle)
data4 <- data.frame(x4 = x, y4 = y)
data <- cbind(data1, data2, data3, data4)
p <- ggplot(data, aes(x = x, y = y))
p + geom_polygon(fill = "white", colour = "black") + geom_polygon(aes(x=x2, y=y2), fill = "black") +
geom_polygon(aes(x=x3, y = y3), fill = "white") +
geom_polygon(aes(x=x4, y = y4), fill = "black") +
opts(axis.title.x = theme_blank(), axis.title.y = theme_blank(),
panel.background = theme_blank(), axis.text.x = theme_blank(),
axis.text.y = theme_blank(), axis.ticks = theme_blank(),
panel.grid.minor = theme_blank())
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment