Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
Three circles
circleFunc <-
function(center = c(0,0), diameter = 1, npoints = 100, start = 0, end = 2*pi) {
tt <- seq(start, end, length.out = npoints)
data.frame(x = center[1] + diameter / 2 * cos(tt),
y = center[2] + diameter / 2 * sin(tt))
}
add.alpha <- function(col, alpha = 1) {
if(missing(col))
stop("Please provide a vector colors.")
apply(sapply(col, col2rgb)/255, 2, function(x)
rgb(x[1], x[2], x[3], alpha = alpha))
}
radius <- 100
c1 <- circleFunc(diameter = radius*2)
c2 <- circleFunc(diameter = radius*2, center = c(radius,0))
c3 <- circleFunc(diameter = radius*2, center = c(radius/2, -sqrt(radius^2-(radius/2)^2)))
plot.new()
plot.window(c(-100,200), c(-200,100))
polygon(c1, col = add.alpha("lightblue", 0.8))
polygon(c2, col = add.alpha("pink", 0.6))
polygon(c3, col = add.alpha("lightgreen", 0.4))
text(x = -radius/2, y = radius / 4, "Bank Robbers")
text(x = radius/2, y = radius / 4, "Everybody on the floor")
text(x = radius*1.5, y = radius / 4, "DJ's")
text(x = radius/2, y = -radius/4, "Put your hands up")
text(x = -radius/8, y = -radius/2, "Give me\nyour money")
text(x = radius*1.1, y = -radius/2, "Are you\nwith me?")
text(x = radius/2, y = -radius*1.25, "Preachers")
@MartinMSPedersen

This comment has been minimized.

Copy link
Owner Author

MartinMSPedersen commented Jan 21, 2019

This example shows how to

  • Draw circles
  • Blending colors using alpha-values
  • Annotating graphics

with basic R graphics.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.