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

add colour to geom_boxplot in geom_fruit? #27

Open
michoug opened this issue Dec 8, 2022 · 1 comment
Open

add colour to geom_boxplot in geom_fruit? #27

michoug opened this issue Dec 8, 2022 · 1 comment

Comments

@michoug
Copy link

michoug commented Dec 8, 2022

Hi,
I'm trying to color the geom_boxplot in geom_fruit within an aes, but it doesn't seem to work.
here below an example of my code, where the fill= Phylum works but not the color = Phylum, as the color of the outside of the box is just black.

library(ggtree)
library(phyloseq)
library(dplyr)

data("GlobalPatterns")
GP <- GlobalPatterns
GP <- prune_taxa(taxa_sums(GP) > 600, GP)
sample_data(GP)$human <- get_variable(GP, "SampleType") %in%
  c("Feces", "Skin")
mergedGP <- merge_samples(GP, "SampleType")
mergedGP <- rarefy_even_depth(mergedGP,rngseed=394582)
mergedGP <- tax_glom(mergedGP,"Order")

melt_simple <- psmelt(mergedGP) %>%
  filter(Abundance < 120) %>%
  select(OTU, val=Abundance)

p <- ggtree(mergedGP, layout="fan", open.angle=10) + 
  geom_tippoint(mapping=aes(color=Phylum), 
                size=1.5,
                show.legend=FALSE)
p <- rotate_tree(p, -90)

p <- p +
  geom_fruit(
    data=melt_simple,
    geom=geom_boxplot,
    mapping = aes(
      y=OTU,
      x=val,
      group=label,
      fill=Phylum, color = Phylum
    ),
    size=.2,
    outlier.size=0.5,
    outlier.stroke=0.08,
    outlier.shape=21,
    axis.params=list(
      axis       = "x",
      text.size  = 1.8,
      hjust      = 1,
      vjust      = 0.5,
      nbreak     = 3,
    ),
    grid.params=list()
  ) 
p

While, with just ggplot2 it works well

ggplot(mpg, aes(x=class, y=hwy, fill = class, color = class)) + 
  geom_boxplot(alpha=0.2)

Any ideas?
Thanks a lot
Greg

@xiangpin
Copy link
Member

xiangpin commented Dec 9, 2022

This is beacuse the color aesthetic was used in the internal function of ggtreeExtra (The design was to solve the problem caused by combing the discrete and continuous values). So, here, the color aesthetics of geom_boxplot was not adjusted by scale_color_manual. But the color aesthetics of geom_tippoint can be adjusted by adding scale_color_manual.

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

No branches or pull requests

2 participants