Skip to content
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

Figure label moves depending on length of text using annotate_figure #185

Open
al-obrien opened this issue Jun 6, 2019 · 1 comment
Open

Comments

@al-obrien
Copy link

al-obrien commented Jun 6, 2019

I have made several plots and each has a label using annotate_figure. However, I noticed that if my labels are of varying length, the position of the text will translate to the right. This makes the alignment of my figure captions differ between my images.

For example, adjusting some code from the documentation:

a. Short Label

data("ToothGrowth")
df <- ToothGrowth
df$dose <- as.factor(df$dose)

# Box plot
bxp <- ggboxplot(df, x = "dose", y = "len",
    color = "dose", palette = "jco")
# Dot plot
dp <- ggdotplot(df, x = "dose", y = "len",
    color = "dose", palette = "jco")
# Density plot
dens <- ggdensity(df, x = "len", fill = "dose", palette = "jco")

# Arrange and annotate
figure <- ggarrange(bxp, dp, dens, ncol = 2, nrow = 2)
annotate_figure(figure,
               left = text_grob("Figure arranged using ggpubr", color = "green", rot = 90),
               fig.lab = "Short Label", fig.lab.face = "bold" # Short Label Length
)

image

b. Long Label

data("ToothGrowth")
df <- ToothGrowth
df$dose <- as.factor(df$dose)

# Box plot
bxp <- ggboxplot(df, x = "dose", y = "len",
    color = "dose", palette = "jco")
# Dot plot
dp <- ggdotplot(df, x = "dose", y = "len",
    color = "dose", palette = "jco")
# Density plot
dens <- ggdensity(df, x = "len", fill = "dose", palette = "jco")

# Arrange and annotate
figure <- ggarrange(bxp, dp, dens, ncol = 2, nrow = 2)
annotate_figure(figure,
               left = text_grob("Figure arranged using ggpubr", color = "green", rot = 90),
               fig.lab = "I AM A SUPER SUPER SUPER DUPER LONG LABEL LOOK AT ME..............................", fig.lab.face = "bold" # Long Label Length
)

image

@al-obrien
Copy link
Author

al-obrien commented Jun 7, 2019

Solution was provided from a related post. However, I am not sure if the annotate_figure function allows for this particular solution to work. Directly working with cowplot may be easier. Perhaps allowing additional parameters to be passed to p <- cowplot::ggdraw(p) + do.call(cowplot::draw_figure_label, lab.args) from annotate_figure would be a solution.

@al-obrien al-obrien reopened this Jun 7, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant