Hello,
This may reek of an ”asked and answered” post but please bear with me – after hours of searching and failed attempts, have not found a solution. Need to label facets with mix of regular text and subscript—there are clearly ways to do this using calls to “annotate” or ”expression.” But for this plot need to label facets for a subset of the data – to date I’ve only been able to do this using geom_text.
# data file attached (df1.csv). “id” variables created to allow crisp (vs. ugly overwritten) facet labels. Even if there is a more elegant way to do this -- in which case please advise! -- for other reasons it’s necessary to subset these data
Main plot call:
> p1 <- ggplot(df1, aes(SC, depth))
+ geom_point()
+ facet_wrap(~well, scales="free")
+ geom_path()
+ scale_y_reverse()
+ geom_segment(data=df1, aes(x=-Inf, xend=-Inf, y=tscr, yend=bscr))
+ labs(x="SC (\u03BCS/cm)", y="Depth (bgs)", title="SC profiles in well subset; left vertical line denotes screened interval (SI)", subtitle=expression(paste("Desired facet label format: ", CV[SI]," = …")))
# line of code I’m trying to figure out…
p1 + geom_text(data=df1[df1$interval=="scr" & df1$id2=="1",], aes(x = Inf, y = -Inf, label = paste("CVSI =", cv2)), size=3, vjust=2, hjust=1.1)
How change CVSI to CVSI AND retain capacity to subset the data?? Suspect there’s an easy answer, but this one eludes me.
many thanks,
Susan
ggplot(df1, aes(SC, depth))
+ geom_point()
+ facet_wrap(~well, scales="free")
+ geom_path()
+ scale_y_reverse()
+ geom_segment(data=df1, aes(x=-Inf, xend=-Inf, y=tscr, yend=bscr))
+ labs(x="SC (\u03BCS/cm)", y="Depth (bgs)", title="SC profiles in well subset; left vertical line denotes screened interval (SI)", subtitle=expression(paste("Desired facet label format: ", CV[SI]," = …")))
geom_text(data=df1[df1$interval=="scr" & df1$id2==1,], aes(x=Inf, y=-Inf, label = paste("CVSI =", cv2)), size=3, vjust=2, hjust=1.1)