R/get_binInfo.R

Defines functions get_binInfo

get_binInfo <- function(data, origin, active, binwidth, yshows) {
  
  which_is_active <- which(active)
  data <- data[active]
  n <- length(data)
  binId <- list()
  min_x <- min(data)
  start_bin <- if(origin >= min_x) {
    i <- 0
    while (min_x + i * binwidth < origin) i <- i + 1
    origin - i * binwidth
  } else {
    i <- 0
    while (origin + i * binwidth < min_x) i <- i + 1
    origin + (i-1) * binwidth
  }
  end_bin <- max(data)
  
  i <- 1
  binX <- c()
  while(start_bin + (i-1) * binwidth <= end_bin){
    left <- start_bin + (i - 1) * binwidth
    right <- start_bin + i * binwidth
    binId[[i]] <- which_is_active[which((data < right & data >= left) == TRUE)]
    binX <- c(binX, left, right)
    i <- i + 1
  }
  
  binHeight <- if(yshows == "frequency") sapply(binId, "length") else sapply(binId, "length") / (n * binwidth)
  
  list(
    binId = binId,
    binX = unique(binX),
    binHeight = binHeight
  )
}

Try the loon.shiny package in your browser

Any scripts or data that you put into this service are public.

loon.shiny documentation built on Oct. 8, 2022, 5:05 p.m.