ggtreeExtra
ggtreeExtra copied to clipboard
add colour to geom_boxplot in geom_fruit?
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
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.