#' Plotting function for compositional data
#'
#' Plotting function for compositional data
#' @param x x coordinate
#' @param y y coordinate
#' @param comp composition vector
#' @param color color scale, same dimension as comp
#' @param radius radius of the circle
#' @keywords estimation
#' @export
#' @examples
compCircle = function(x,y,comp, color = rainbow(4), radius){
if(length(x)==1){
full.circle = cbind(x+(radius)*cos(seq(0,2*pi,length.out = 10000)), y+(radius)*sin(seq(0,2*pi,length.out = 10000)))
prev = 0
for(i in 1:length(comp)){
index.start = min(prev+1, 10000)
index.end = min(prev + round(comp[i]*10000),10000)
x.ci = c(x, full.circle[index.start:index.end,1] , x)
y.ci = c(y, full.circle[index.start:index.end,2] , y)
polygon(x.ci, y.ci, border=NA, col = color[i])
prev = min(prev + round(comp[i]*10000), 10000)
}
}
if(length(x)>1){
for(i in 1:length(x)){
full.circle = cbind(x[i]+(radius)*cos(seq(0,2*pi,length.out = 10000)), y[i]+(radius)*sin(seq(0,2*pi,length.out = 10000)))
prev = 0
for(j in 1:length(comp[i,])){
index.start = min(prev+1, 10000)
index.end = min(prev + round(comp[i,j]*10000),10000)
x.ci = c(x[i], full.circle[index.start:index.end,1] , x[i])
y.ci = c(y[i], full.circle[index.start:index.end,2] , y[i])
polygon(x.ci, y.ci, border=NA, col = color[j])
prev = min(prev + round(comp[i,j]*10000), 10000)
}
}
}
}
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.