Skip to content

Commit

Permalink
add circos.triangles()
Browse files Browse the repository at this point in the history
  • Loading branch information
jokergoo committed Oct 17, 2019
1 parent de384e6 commit 0cd7895
Show file tree
Hide file tree
Showing 203 changed files with 2,524 additions and 271 deletions.
2 changes: 1 addition & 1 deletion DESCRIPTION
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ Package: circlize
Type: Package
Title: Circular Visualization
Version: 0.4.9
Date: 2019-09-05
Date: 2019-10-17
Author: Zuguang Gu
Maintainer: Zuguang Gu <[email protected]>
Depends: R (>= 3.0.0), graphics
Expand Down
1 change: 1 addition & 0 deletions NAMESPACE
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@ export("circos.trackLines")
export("circos.trackPlotRegion")
export("circos.trackPoints")
export("circos.trackText")
export("circos.triangle")
export("circos.update")
export("circos.updatePlotRegion")
export("circos.xaxis")
Expand Down
3 changes: 3 additions & 0 deletions NEWS
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
Changes in version 0.4.9
-----------------------------------------------------------------------
* `chordDiagram()`: fixed a bug when `link.overlap = TRUE` for sparse matrices.
* `circos.rect()`: add `rot` argument.
* add `circos.triangle()`.
* all examples are included in R source code files

Changes in version 0.4.8
-----------------------------------------------------------------------
Expand Down
59 changes: 28 additions & 31 deletions R/chordDiagram.R
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,21 @@
# -``x1`` and position of the link on the "from" sector, the interval for the link on the "from" sector is ``c(x1-abs(value), x1)``
# -``x2`` and position of the link on the "to" sector, the interval for the link on the "from" sector is ``c(x2-abs(value), x2)``
#
# == examples
# set.seed(999)
# mat = matrix(sample(18, 18), 3, 6)
# rownames(mat) = paste0("S", 1:3)
# colnames(mat) = paste0("E", 1:6)
#
# df = data.frame(from = rep(rownames(mat), times = ncol(mat)),
# to = rep(colnames(mat), each = nrow(mat)),
# value = as.vector(mat),
# stringsAsFactors = FALSE)
#
# chordDiagram(mat)
# chordDiagram(df)
# circos.clear()
#
chordDiagram = function(x, grid.col = NULL, grid.border = NA, transparency = 0.5,
col = NULL, row.col = NULL, column.col = NULL,
order = NULL, directional = 0, xmax = NULL,
Expand Down Expand Up @@ -230,37 +245,6 @@ parsePreAllocateTracksValue = function(preAllocateTracks) {
return(mat)
}

# title
# Adjust gaps to make chord diagrams comparable
#
# == param
# -mat1 matrix that has the largest sum of absolute
# -gap.degree gap.degree for the Chord diagram which corresponds to ``mat1``
# -start.degree start.degree for the first Chord diagram
# -mat2 matrix to be compared
#
# == details
# Normally, in Chord Diagram, values in mat are normalized to the summation and each value is put
# to the circle according to its percentage, which means the width for each link only represents
# kind of relative value. However, when comparing two Chord Diagrams, it is necessary that unit
# width of links in the two plots should be represented in a same scale. This problem can be solved by
# adding more blank gaps to the Chord Diagram which has smaller values.
#
# == value
# Sum of gaps for ``mat2``.
#
normalizeChordDiagramGap = function(mat1, gap.degree = circos.par("gap.degree"),
start.degree = circos.par("start.degree"), mat2) {
percent = sum(abs(mat2)) / sum(abs(mat1))

if(length(gap.degree) == 1) {
gap.degree = rep(gap.degree, length(unique(rownames(mat1), colnames(mat1))))
}
blank.degree = (360 - sum(gap.degree)) * (1 - percent)
big.gap = (blank.degree - sum(rep()))/2
return(blank.degree)
}

mat2df = function(mat) {
nr = dim(mat)[1]
nc = dim(mat)[2]
Expand Down Expand Up @@ -346,6 +330,9 @@ mat2df = function(mat) {
# == value
# A data frame which contains positions of links, see explanation in `chordDiagram`.
#
# == seealso
# http://jokergoo.github.io/circlize_book/book/the-chorddiagram-function.html
#
chordDiagramFromMatrix = function(mat, grid.col = NULL, grid.border = NA, transparency = 0.5,
col = NULL, row.col = NULL, column.col = NULL, order = NULL, directional = 0,
direction.type = "diffHeight", diffHeight = convert_height(2, "mm"),
Expand Down Expand Up @@ -683,6 +670,9 @@ chordDiagramFromMatrix = function(mat, grid.col = NULL, grid.border = NA, transp
# == value
# A data frame which contains positions of links, see explanation in `chordDiagram`.
#
# == seealso
# http://jokergoo.github.io/circlize_book/book/the-chorddiagram-function.html
#
chordDiagramFromDataFrame = function(df, grid.col = NULL, grid.border = NA, transparency = 0.5,
col = NULL, order = NULL, directional = 0, xmax = NULL,
direction.type = "diffHeight", diffHeight = convert_height(2, "mm"),
Expand Down Expand Up @@ -1176,6 +1166,13 @@ psubset = function(mat, ri, ci) {
# == value
# A numeric value which can be directly set to ``big.gap`` in the second Chord diagram.
#
# == examples
# set.seed(123)
# mat1 = matrix(sample(20, 25, replace = TRUE), 5)
# mat2 = mat1 / 2
# gap = calc_gap(mat1, mat2, big.gap = 10, small.gap = 1)
# chordDiagram(mat2, directional = 1, grid.col = rep(1:5, 2), transparency = 0.5,
# big.gap = gap, small.gap = 1)
calc_gap = function(x1, x2, big.gap = 10, small.gap = 1) {
if(is.matrix(x1)) {
sum1 = sum(abs(x1))
Expand Down
21 changes: 12 additions & 9 deletions R/circos.arrow.R
Original file line number Diff line number Diff line change
Expand Up @@ -23,30 +23,33 @@
#
# If you see points overflow warnings, you can set ``circos.par(points.overflow.warning = FALSE)`` to turn it off.
#
# == seealso
# https://jokergoo.github.io/circlize_book/book/graphics.html#circular-arrows
#
# == author
# Zuguang Gu <[email protected]>
#
# == example
# circos.initialize(letters[1:4], xlim = c(0, 1))
# circos.track(ylim = c(0, 1), panel.fun = function(x, y) {
# circos.arrow(0, 1, y = 0.5, width = 0.4, arrow.head.length = ux(1, "cm"),
# col = "red", tail = ifelse(CELL_META$sector.index \%in\% c("a", "c"),
# "point", "normal"))
# circos.arrow(0, 1, y = 0.5, width = 0.4, arrow.head.length = ux(1, "cm"),
# col = "red", tail = ifelse(CELL_META$sector.index \%in\% c("a", "c"),
# "point", "normal"))
# }, bg.border = NA, track.height = 0.4)
#
# ########## cell cycle ###########
# cell_cycle = data.frame(phase = factor(c("G1", "S", "G2", "M"),
# levels = c("G1", "S", "G2", "M")),
# hour = c(11, 8, 4, 1))
# hour = c(11, 8, 4, 1))
# color = c("#66C2A5", "#FC8D62", "#8DA0CB", "#E78AC3")
# circos.par(start.degree = 90)
# circos.initialize(cell_cycle$phase, xlim = cbind(rep(0, 4), cell_cycle$hour))
# circos.track(ylim = c(0, 1), panel.fun = function(x, y) {
# circos.arrow(CELL_META$xlim[1], CELL_META$xlim[2],
# arrow.head.width = CELL_META$yrange*0.8, arrow.head.length = ux(1, "cm"),
# col = color[CELL_META$sector.numeric.index])
# circos.text(CELL_META$xcenter, CELL_META$ycenter, CELL_META$sector.index,
# facing = "downward")
# circos.arrow(CELL_META$xlim[1], CELL_META$xlim[2],
# arrow.head.width = CELL_META$yrange*0.8, arrow.head.length = ux(1, "cm"),
# col = color[CELL_META$sector.numeric.index])
# circos.text(CELL_META$xcenter, CELL_META$ycenter, CELL_META$sector.index,
# facing = "downward")
# }, bg.border = NA, track.height = 0.3)
# circos.clear()
#
Expand Down
12 changes: 11 additions & 1 deletion R/circos.nested.R
Original file line number Diff line number Diff line change
Expand Up @@ -234,8 +234,18 @@ ring: ", paste0(f2_sectors, collapse = ', '), ".\n"))
dev.off2 = function () {
i1 = dev.prev()
i2 = dev.cur()
if (i1 > 1)
if (i1 == 2) {
dev.set(i1)
}
else if (i1 > 2) {
i11 = dev.prev(i1)
if (names(i11) == "RStudioGD") {
dev.set(i11)
}
else {
dev.set(i1)
}
}
dev.off(i2)
}

Expand Down
Loading

0 comments on commit 0cd7895

Please sign in to comment.