Skip to content
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

annotation of circular trees #78

Closed
Ekie22 opened this issue Oct 5, 2016 · 17 comments
Closed

annotation of circular trees #78

Ekie22 opened this issue Oct 5, 2016 · 17 comments
Labels

Comments

@Ekie22
Copy link

Ekie22 commented Oct 5, 2016

Hi, thanks for the nice package, I like to use it for circular trees. However, I have some issues annotating circular trees (using ggtree version 1.4.20).

  1. I want to show aligned tip labels with geom_tip2 but the nodes are always shown too.
    load tree from tree annotation documentation:
    library("ggplot2")
    library("ggtree")
    nwk <- system.file("extdata", "sample.nwk", package="ggtree")
    tree <- read.tree(nwk)
    circ <- ggtree(tree, layout = "circular")
    without align:
    circ + geom_tiplab2(size=2.5, color="black")
    with align:
    circ + geom_tiplab2(size=2.5, color="black", align=TRUE)
    How do I prevent that the nodes are shown? I also tested it with subset:
    circ + geom_tiplab2(size=2.5, aes(subset=isTip), color="black", align=TRUE)
    but that did not work either.

  2. Increase resolution of circular tree after a node was collapsed
    At the moment the space of a collapsed clade remains empty in the circle:
    circ %>% collapse(node=21) + geom_point2(aes(subset=(node == 21)), size=5, shape=23, fill="steelblue")
    Is it possible circularise the tree again (extend a circular tree over the whole circle) after a clade was collapsed? At the moment I drop the tips in the original phylo object and draw the resulting tree from scratch but this is rather laborious.

  3. Adapt angle of tip labels after rotate
    The angle of aligned tip labels seem to refer to the original position (see example below).
    generate long tip names:
    circ$data$label <- c(paste(circ$data$label[1:13], "aaaa", sep=""), circ$data$label[14:length(circ$data$label)])
    tip label orientation before rotate:
    circ + geom_tiplab(size=2.5, color="black", align=TRUE, aes(angle=angle))
    tip label orientation after rotate:
    rotate(circ, 16) + geom_tiplab(size=2.5, color="black", align=TRUE, aes(angle=angle))
    Is it possible to angle the tip labels according to the new position preferable with geom_tiplab2?

  4. Add two independently coloured heatmaps with separate legends with gheatmap to a circular tree
    I would like to do something like the following:
    external data which should be added:
    df <- data.frame(first=c("a", "b", "a", "c", "d", "d", "a", "b", "e", "e", "f", "c", "f"), second= c("z", "z", "z", "z", "y", "y", "y", "y", "x", "x", "x", "a", "a")) row.names(df) <- circ$data[circ$data$isTip=="TRUE", "label"]
    first heatmap with manual colour palette:
    library("RColorBrewer") p1 <- gheatmap(circ, df[,"first", drop=FALSE], offset = 0.8, width=0.1) + scale_fill_brewer(palette= "Dark2") p1
    add second heatmap with another colour palette:
    gheatmap(p1, df[,"second", drop=FALSE], offset = 5, width=0.1) + scale_fill_brewer(palette= "Pastel1")
    results in the warning:

Scale for 'fill' is already present. Adding another scale for 'fill', which will replace the existing scale.

Both circles are coloured according to the last palette and one legend for all entries is generated. For similar entries (a) this can be confusing. Is it possible to add several independently controllable heatmaps?
Thanks.

@GuangchuangYu
Copy link
Member

pls follow the guide and provide minimal reproducible example, thanks.

@Ekie22
Copy link
Author

Ekie22 commented Oct 6, 2016

In my example I used your tree from the tree annotation documentation. I added the library and import information. Is anything further needed?

@GuangchuangYu
Copy link
Member

GuangchuangYu commented Oct 6, 2016

1). I can't reproduce your issue:

screen shot 2016-10-06 at 7 29 27 pm


2. & 3. are bugs need to be fixed.


4). This is not an issue of ggtree. This feature is not supported by ggplot2.

> ggplot(df[, 'first', drop=FALSE]) + geom_bar(aes(x=first, fill=first)) + scale_fill_brewer(palette= "Dark2")+ geom_bar(data=df[, 'second', drop=F], aes(x=second, fill=second))+ scale_fill_manual(palette= "Pastel1")
Scale for 'fill' is already present. Adding another scale for 'fill', which
will replace the existing scale.
Error in f(..., self = self) : attempt to apply non-function

@Ekie22
Copy link
Author

Ekie22 commented Oct 6, 2016

  1. When I run the code (R version 3.3.1), I get the following output:
    screenshot_issue1

@GuangchuangYu
Copy link
Member

what's your ggplot2 version?

@Ekie22
Copy link
Author

Ekie22 commented Oct 6, 2016

ggplot2 version 2.1.0

@GuangchuangYu
Copy link
Member

I don't have Windows machine and can't reproduce your issue in either Linux or OSX.

BTW: issue 2 & 3 were fixed in ggtree (version >= 1.5.15).

@GuangchuangYu
Copy link
Member

for issue 4, you can use something like this:

screen shot 2016-10-06 at 7 49 57 pm

@Ekie22
Copy link
Author

Ekie22 commented Oct 7, 2016

Thanks, I am doing that. I just hoped for a possibility to separate the legends of the two circles.

@Ekie22
Copy link
Author

Ekie22 commented Oct 10, 2016

Hi,

I tried to install the ggtree (version >= 1.5.15) with
"install_github("GuangchuangYu/ggtree")" but got the following error:

Downloading GitHub repo GuangchuangYu/ggtree@master from URL
https://api.github.com/repos/GuangchuangYu/ggtree/zipball/master
Installing ggtree "C:/PROGRA1/R/R-331.1/bin/x64/R" --no-site-file
--no-environ --no-save --no-restore --quiet CMD INSTALL \
"d:/user/hef12/AppData/Local/Temp/RtmpcregwL/devtools12c010f9224f/GuangchuangYu-ggtree-51aff5a"
\ --library="D:/user/hef12/Documents/R-dev" --install-tests * installing source package 'ggtree' ...
** R
** inst
** tests
** byte-compile and prepare package for lazy loading
Note: wrong number of arguments to '>'
Note: possible error in 'layer(stat = StatBalance, ':
unbenutztes Argument (check.aes = FALSE)
Note: possible error in 'layer(stat = StatBalance, ':
unbenutztes Argument (check.aes = FALSE)
Note: possible error in 'layer(stat = StatHilight, ':
unbenutztes Argument (check.aes = FALSE)
Note: possible error in 'layer(data = data, mapping = mapping, ':
unbenutztes Argument (check.aes = FALSE)

.....

When I try to use ggtree (ggtree(tree, layout = "circular")) it gives
the following error:

Error in layer(data = data, mapping = mapping, stat =
StatTreeHorizontal, : unused argument (check.aes = FALSE)

Do I have to install it in a differnt way?

Thanks

Am 10.10.2016 um 15:12 schrieb Guangchuang Yu:

Closed #78 #78.


You are receiving this because you authored the thread.
Reply to this email directly, view it on GitHub
#78 (comment),
or mute the thread
https://github.com/notifications/unsubscribe-auth/AVlrLwJzLcBfs7qw4T8PvyY6YBWw5GXNks5qyjm3gaJpZM4KOz3e.

@GuangchuangYu
Copy link
Member

You need to install github version of ggplot2 by:

install_github("hadley/ggplot2")

@Ekie22
Copy link
Author

Ekie22 commented Oct 10, 2016

Thanks. With this version issue 1 also works fine.

@GuangchuangYu
Copy link
Member

library("ggplot2")
library("ggtree")

nwk <- system.file("extdata", "sample.nwk", package="treeio")

tree <- read.tree(nwk)
circ <- ggtree(tree, layout = "circular")

df <- data.frame(first=c("a", "b", "a", "c", "d", "d", "a", "b", "e", "e", "f", "c", "f"),
                 second= c("z", "z", "z", "z", "y", "y", "y", "y", "x", "x", "x", "a", "a"))

rownames(df) <- tree$tip.label


p1 <- gheatmap(circ, df[, "first", drop=F], offset=.8, width=.1,
               colnames_angle=90, colnames_offset_y = .25)
p2 <- gheatmap(p1, df[, "second", drop=F], offset=5, width=.1,
               colnames_angle=90, colnames_offset_y = .25)

require(RColorBrewer)
col <- c(brewer.pal(5, "Dark2"), brewer.pal(4, "Pastel1"))
names(col) = c(letters[1:6], letters[24:26])

pp <- p2 + scale_fill_manual(values=col)

p1x <- p1 + scale_fill_manual(values=col)
p2x <- gheatmap(circ, df[, "second", drop=F], offset=5, width=.1) +
    scale_fill_manual(values=col) 

require(cowplot)
leg1 <- get_legend(p1x)
leg2 <- get_legend(p2x)

pp <- pp + theme(legend.position="none")
plot_grid(pp, leg1, leg2, ncol=3, rel_widths=c(1, .1, .1))

separate_legend

@shigdon
Copy link

shigdon commented Feb 13, 2019

Hi @GuangchuangYu,

This is a really great example. I am trying to adapt the strategy you used to make a similar plot with two gheatmaps on the outside of a ggtree, but I'd like the data in the gheatmaps to be continuous rather than discrete (numerical values from biological assays). Is there a way to do this? It would be ideal to have multiple heatmaps with different gradient color scales. I have the data arranged in a dataframe, where rows are samples and each column holds numerical data for each sample's performance in a bioassay.

I try to use the built in high and low options of gheatmap, but when I do this the scale of the first gheatmap seems to get replaced by that of the second gheatmap.

I've tried looking through the issues on github and performed many string searches online, but haven't really found any solution yet.

Any advice, suggestions or guidance would be really appreciated.

Thanks for making this really great package!

UPDATE: I saw that there is a google forum for this package, so I have posted the same question there. Here is the link

@GuangchuangYu
Copy link
Member

@ksw9
Copy link

ksw9 commented Jun 12, 2019

Hi,
Thank you very much for the above example. I am trying to do a similar thing with the only addition that I'd like to add legend titles for each heat map ring. I tried using the above code, adding the following change, but have not been able to produce a legend title.

 gheatmap(circ, df[, "second", drop=F], offset=5, width=.1) +
    scale_fill_manual(values=col, name = 'test') 

Thank you in advance for your suggestions!
Best,

@GuangchuangYu
Copy link
Member

pls refer to the ggtreeExtra package for circular tree annotation.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

4 participants