Skip to content

two issues about geom_bar with the same number #2

@xiayh17

Description

@xiayh17
library("ggplot2")
library("ggtree")
library("ggtreeExtra")

#tree
trfile <- system.file("extdata", "tree.nwk", package="ggtreeExtra")
tr <- read.tree(trfile)
numtip <- length(tr$tip.label)

#data
dat2 <- data.frame(ID=tr$tip.label,
                   Location=c(rep("HK", 50), rep("TW", 36), rep("SX", 30), rep("GD", 48),
                              rep("HN", 20), rep("AH", 20), rep("FJ", 26)),
                   Length=abs(rnorm(n=numtip, mean=0.6)),
                   Group=c(rep("Yes", 200), rep("No", 30)),
                   Abundance=abs(rnorm(n=numtip, mean=10, sd=0.00000001)))

p <- ggtree(tr, layout="circular", size=0.1) + geom_treescale(x=6, y=0, fontsize=1.2, linesize=0.3)

p + geom_fruit(data=dat2,
               geom=geom_bar,
               mapping=aes(y=ID, x=Abundance, fill=Location),
               width=1,
               stat="identity",
               orientation="y") +
  scale_fill_manual(values=c("#D15FEE","#EE6A50","#FFC0CB","#8E8E38","#9ACD32","#006400","#8B4513"),
                    guide=guide_legend(keywidth=0.5, keyheight=0.5, order=6)) +
  theme(legend.position=c(0.95, 0.5),
        legend.title=element_text(size=7),
        legend.text=element_text(size=6),
        legend.spacing.y = unit(0.02, "cm"))

image

There are two issues about using the geom_fruit plot bar plot
1.
The code can be run smoothly. But the results confuse me a bit. The values of the bars are almost the same, so why do they look so uneven? Shouldn't these bars be the same length?

I try to set Abundance to the same value, for example:
Abundance=rep(10,times=numtip)
In this case there is an error that occurs.
image

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions