-
Notifications
You must be signed in to change notification settings - Fork 146
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
integrate chordDiagram() with ggdraw function to combine ggplot objects #339
Comments
circlize is implemented with the base graphics. To be combined it with the ggplot2 plots, you need to use gridBase package. |
@zh-zhang1984 it turns out you can pass it as a formula with library(patchwork)
library(ggplot2)
library(circlize)
p1 <- ggplot(mtcars) + geom_point(aes(mpg, disp))
mat = matrix(1:9, 3)
rownames(mat) = letters[1:3]
colnames(mat) = LETTERS[1:3]
p1 + wrap_elements(full = ~ chordDiagram(mat)) However, @jokergoo , I have a problem if I want to rotate the text per the book: p2 = ~ chordDiagram(mat, annotationTrack = "grid",
preAllocateTracks = list(track.height = max(strwidth(unlist(dimnames(mat))))),
directional = 1, direction.type = c("diffHeight", "arrows"),
link.arr.type = "big.arrow")
title("I want a title")
# we go back to the first track and customize sector labels
circos.track(track.index = 1, panel.fun = function(x, y) {
circos.text(CELL_META$xcenter, CELL_META$ylim[1], CELL_META$sector.index,
facing = "clockwise", niceFacing = TRUE, adj = c(0, 0.5))
}, bg.border = NA) # here set bg.border to NA is important
p1 + wrap_elements(full=p2) It will not accept the additional base graphics, nor the annotation track: Error in title("I want a title") : plot.new has not been called yet
Error in polygon(polar2Cartesian(d2), ...) :
plot.new has not been called yet |
@rbutleriii if you do so, wrap all the base graphics code into a code block: p2 = ~ {
chordDiagram(mat, annotationTrack = "grid",
preAllocateTracks = list(track.height = max(strwidth(unlist(dimnames(mat))))),
directional = 1, direction.type = c("diffHeight", "arrows"),
link.arr.type = "big.arrow")
title("I want a title")
# we go back to the first track and customize sector labels
circos.track(track.index = 1, panel.fun = function(x, y) {
circos.text(CELL_META$xcenter, CELL_META$ylim[1], CELL_META$sector.index,
facing = "clockwise", niceFacing = TRUE, adj = c(0, 0.5))
}, bg.border = NA) # here set bg.border to NA is important
} I haven't used patchwork, but I guess it should work. |
Excellent! Yes that does work to wrap the whole thing: Also, the link to the grid/cowplot method: |
Suppose I have several
ggplot2
objects and I want to combine all panel figures in a large figure; other figures are generated withggplot2
. Are there any efficient method to do so; I found thechordDiagram()
returned adata.frame
object.The text was updated successfully, but these errors were encountered: