I have a code like this
#creating a categorical variable from a continuous one.
lobxx <- Loblolly %>%
mutate(ageG = if_else(age < 10,"A", if_else(age == 10, "B", if_else(age > 10, "C", "NA"))))
#calculating the t value
dfxx <- lobxx %>%
rstatix::df_arrange(ageG,age) %>%
rstatix::t_test(height~ageG) %>%
rstatix::add_xy_position(x="ageG")
#creating a plot using ggplot and ggpubr::geom_bracket
dfxplotx <- ggplot(lobxx,aes(x= reorder(ageG,-height),y=height,fill=ageG))+
stat_summary(geom="col",fun = mean)+
ggpubr::geom_bracket(mapping=aes(xmin = group1, xmax = group2),data = dfxx,
label = glue("P:{dfxx$p.adj}{dfxx$p.adj.signif}"),
y.position = c(53,60,53),
bracket.nudge.y = 5,inherit.aes = F)
dfxplotx
You can notice that I used the dollar sign to refer to the data frame. The point is that I noticed that most examples on the web did not use a format like this (data frame $ variable). Is there something wrong with the code or has something changed elsewhere? thank you.
I tried this code without using the $ sing in the glue function but I had error message. Why should this happen.
an alternative to $ syntax for pulling things out of lists is square brackets. When they both work there is no benefit to using one or the other apart from style/habit. However square bracket syntax is more general / powerful, as it can be used directly for metaprogramming; i.e. writing code which relies on the contents of variables to do one thing or another. Here is an example