-
Notifications
You must be signed in to change notification settings - Fork 15
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
can ggtreeExtra add errorbar for geom_bar #15
Comments
Yes, but the using geomExtra
You can also use
|
Great Job. Thanks very much ! Best wishes to Yu LAB.
At 2021-09-16 20:54:43, "Shuangbin Xu" ***@***.***> wrote:
Yes, but the xmin or xmax mapping is not supported by ggtreeExtra. However, the geom_errorbar also can be added by controlling the stat parameters. You can refer to the following codes.
using geomExtra
library(ggtree)
library(ggtreeExtra)
library(ggplot2)
set.seed(1024)
tr <- rtree(10)
dat <- data.frame(id=rep(tr$tip.label, 5), value=abs(rnorm(50)))
df <- data.frame(id=rep(tr$tip.label), group=rep(c("A", "B", "C", "D", "E"), 2))
tr %<>% tidytree::left_join(dat, by=c("label"="id")) %>%
tidytree::left_join(df, by=c("label"="id"))
tr
p1 <- tr %>% ggtree() + geom_tiplab()
p2 <- p1 +
geom_fruit_list(
geom_fruit(
data = td_unnest(value),
geom = geom_bar,
mapping = aes(x = value, fill = group),
stat = "summary",
fun = mean,
orientation = "y",
position = position_identityx(), # This should be position_identidyx() for geom_bar in here.
pwidth = 3, # The pwidth and offset should be equal with geom_errorbar layer.
offset = 0.2
),
geom_fruit(
data = td_unnest(value),
geom = geom_errorbar,
mapping = aes(x = value, group = group),
stat = "summary",
fun.data = "mean_se",
orientation = "y",
position = position_identityx(),
width = 0.2,
pwidth = 3, # pwidth and offset should be equal with geom_bar.
offset = 0.2,
axis.params = list(axis="x", text.size = 3)
)
)
p2
# you can also use point to replace bar plot.
pp2 <- p1 +
geom_fruit_list(
geom_fruit(
data = td_unnest(value),
geom = geom_point,
mapping = aes(x = value, color = group),
stat = "summary",
fun = mean,
orientation = "y",
size = 3,
pwidth = 3, # The pwidth and offset should be equal with geom_errorbar layer.
offset = 0.2
),
geom_fruit(
data = td_unnest(value),
geom = geom_errorbar,
mapping = aes(x = value, group = group),
stat = "summary",
fun.data = "mean_se",
orientation = "y",
position = position_identityx(),
width = 0.2,
pwidth = 3, # pwidth and offset should be equal with geom_bar.
offset = 0.2,
axis.params = list(axis="x", text.size = 3)
)
)
pp2
You can also use geom_facet to display it when the layout of tree is not circular.
f2 <- p1 +
geom_facet(
data = td_unnest(value),
panel = "errorbar",
geom = geom_bar,
mapping = aes(x = value, fill = group),
stat = "summary",
fun = mean,
orientation = "y"
) +
geom_facet(
data = td_unnest(value),
panel = "errorbar",
geom = geom_errorbar,
mapping = aes(x = value, group = group),
stat = "summary",
fun.data = "mean_se",
orientation = "y",
width = 0.2
) +
theme_tree2()
f2
# Using point layer to replace bar plot
library(ggstar)
ff2 <- p1 +
geom_facet(
data = td_unnest(value),
panel = "errorbar",
geom = geom_star,
mapping = aes(x = value, fill = group),
stat = "summary",
fun = mean,
size = 3,
orientation = "y"
) +
geom_facet(
data = td_unnest(value),
panel = "errorbar",
geom = geom_errorbar,
mapping = aes(x = value, group = group),
stat = "summary",
fun.data = "mean_se",
orientation = "y",
width = 0.2
) +
theme_tree2()
ff2
—
You are receiving this because you authored the thread.
Reply to this email directly, view it on GitHub, or unsubscribe.
Triage notifications on the go with GitHub Mobile for iOS or Android.
|
Open
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
sometimes we need to add error_bar for geom_bar, How to make it ?
The text was updated successfully, but these errors were encountered: