Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

Two subtitles in two different positions in ggplot2

In ggplot I have two figures made by facet_wrap and I would like to have two subtitles Versicolor and Virginica left aligned to each figures. How is it possible? I tried James Allison’s How to add multiple captions in ggplot2 outside of the main graph area solution but it was a single figure. Here is what I tried, but I did not get what I want.

iris %>% filter(Species != 'setosa') %>% 
ggplot(aes(x= Petal.Length, y= Petal.Width))+
  geom_point()+
  facet_wrap(~ Species)+
  theme(strip.text.x = element_blank())+ # to get rid of grey box with species names
  labs(subtitle = 'Versicolor') # adding virginica

enter image description here

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

>Solution :

One option would be to fake your subtitles using the strip text:

library(ggplot2)
library(dplyr, warn = FALSE)
iris %>%
  filter(Species != "setosa") %>%
  ggplot(aes(x = Petal.Length, y = Petal.Width)) +
  geom_point() +
  facet_wrap(~Species) +
  theme(
    strip.background.x = element_blank(),
    strip.text.x = element_text(hjust = 0, size = 11)
  )

Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading