Replies: 4 comments 3 replies
-
I've been trying to add curly braces to my plot, indicating a benchmark. I wanted it first to be on the secondary y axis but I didn't find any way to create it. So, I decided to add braces outside the primary y axis. However, since I have grouped data on my x axis, I can't get the braces the way I wanted to be. How can I fix this or is there a way that I could bring the braces on the left side? gplot(benthic_compo,aes(x=Site,y=Percent.Cover,fill=Substrate))+
geom_col(position = "dodge")+
scale_fill_brewer(palette = "Set1")+
guides(fill=guide_legend(reverse=TRUE))+
xlab("SITE")+
theme(panel.grid.minor = element_blank(),
panel.grid.major = element_blank(),
plot.background = element_rect(fill = "transparent", colour = NA))+
geom_text(aes(label=Percent.Cover), position=position_dodge(width=0.9), vjust=-3.0)+
geom_errorbar(aes(ymin = Percent.Cover - se, ymax = Percent.Cover + se),
position = position_dodge(0.9), width = .1)+
scale_y_continuous(
name = "Percent Cover",
breaks = waiver(),
minor_breaks = waiver(),
n.breaks = NULL,
sec.axis = sec_axis(trans = ~.,
name =,
labels =,
))+
geom_brace(aes(y=c(0,5.4), x=c(.4,.7), label="Very Poor"), inherit.data=F, rotate = 270, labelsize = 3)+
geom_brace(aes(y=c(5.5,25.4), x=c(.4,.7), label="Poor"), inherit.data=F, rotate = 270, labelsize = 3)+
geom_brace(aes(y=c(25.4,50.4), x=c(.4,.7), label="Fair"), inherit.data=F, rotate = 270, labelsize = 3)+
geom_brace(aes(y=c(50.5,75.4), x=c(.4,.7), label="Good"), inherit.data=F, rotate = 270, labelsize = 3)+
geom_brace(aes(y=c(75.5,100), x=c(.4,.7), label="Very Good"), inherit.data=F, rotate = 270, labelsize = 3)+
coord_cartesian(y=c(0,100), clip="off")+
theme(plot.margin = unit(c(0.25, 0.11, 0.11, 0.11), units="npc")) |
Beta Was this translation helpful? Give feedback.
-
Hi Nicolas, here is the data I'm trying to work out.
…On Sat, Aug 21, 2021 at 12:47 AM Nicolas Huber ***@***.***> wrote:
Hi, thanks for the question. Would you be willing to share that data here,
so that I can reproduce your example and work directly on that?
—
You are receiving this because you commented.
Reply to this email directly, view it on GitHub
<#1 (reply in thread)>,
or unsubscribe
<https://github.com/notifications/unsubscribe-auth/ANR2UH5EBIF35YNBQDTOJRDT52BI7ANCNFSM4YYGGFOA>
.
Triage notifications on the go with GitHub Mobile for iOS
<https://apps.apple.com/app/apple-store/id1477376905?ct=notification-email&mt=8&pt=524675>
or Android
<https://play.google.com/store/apps/details?id=com.github.android&utm_campaign=notification-email>
.
|
Beta Was this translation helpful? Give feedback.
-
Sorry, here it is. |
Beta Was this translation helpful? Give feedback.
-
I did a minimal example here. First I put all the brace coordinates into a data.frame. This can be used by geom_brace IF the Let me know if this works for you. I am not sure if this is the only issue you had, since you mentioned grouped data. Was there more you wanted to do? library(ggbrace)
library(ggplot2)
benthic_compo <- read.csv("D:/Downloads/benthic_compo.csv")
df_brace <- data.frame(
x=rep(c(-1,0),5),
y=c(0, 5.4, 5.5, 25.4, 25.4, 50.4, 50.5, 75.5, 75.5, 100),
mylabel=rep(c("Very Poor","Poor","Fair","Good","Very Good"), each=2)
)
ggplot(benthic_compo,aes(x=Site,y=Percent.Cover,fill=Substrate))+
geom_col(position = "dodge") +
geom_brace(aes(x,y, label=mylabel, group=mylabel), data=df_brace, inherit.aes=F, rotate = 270, labelsize = 3) +
coord_cartesian(y=c(0,100), x=c(1,4), clip="off") +
theme(plot.margin = unit(c(0.11, 0.11, 0.11, 0.2), units="npc"),
axis.text.x=element_text(angle=45, hjust=1)) |
Beta Was this translation helpful? Give feedback.
-
👋 Welcome!
We’re using Discussions as a place to connect with other members of our community. We hope that you:
build together 💪.
To get started, comment below with an introduction of yourself and tell us about what you do with this community.
Beta Was this translation helpful? Give feedback.
All reactions