R/annotate_circle_ggplot.R

Defines functions annotate_circle_ggplot

Documented in annotate_circle_ggplot

#' Function to help draw a cirle in ggplot2.
#'
#' I found it on the internet, I need to give credit at some point. But this
#' helps to create circles at a specified radius from a cartesian point.
#'
#' This function is not exported.
#'
#' @param radius is the radius
#' @param x_center is the x0 coordiante
#' @param y_center is the y0 coordiante
#' @param color is the color of the line
#' @param fill is whether to fill with a color
#'
#' @return A ggplot2 line object that is a circle.
annotate_circle_ggplot <- function(radius, x_center, y_center, color = "black",
                                   fill = NA, ...) {

  # Set x and y values and and create annotation.
  x <- x_center + radius * cos(seq(0, pi, length.out=100))
  ymin <- y_center + radius * sin(seq(0, -pi, length.out=100))
  ymax <- y_center + radius * sin(seq(0, pi, length.out=100))
  ggplot2::annotate("ribbon", x = x, ymin = ymin, ymax = ymax, color = color,
                    fill = fill, ...)

}
chringer-git/dartboard documentation built on May 29, 2019, 8:34 a.m.