0

Let's assume I have the following data:

data(mpg)
mpg$small_cars<-with(mpg,ifelse(class=="2seater" | class=="compact" | class =="midsize",1,0))
mpg1<-subset(mpg,mpg$class!="suv")
head(mpg1)
ggplot(mpg1, aes(displ, hwy)) +
    geom_point() +
    facet_wrap(vars(class))

# A tibble: 6 x 12
  manufacturer model displ  year   cyl trans      drv     cty   hwy fl    class   small_cars
  <chr>        <chr> <dbl> <int> <int> <chr>      <chr> <int> <int> <chr> <chr>        <dbl>
1 audi         a4      1.8  1999     4 auto(l5)   f        18    29 p     compact          1
2 audi         a4      1.8  1999     4 manual(m5) f        21    29 p     compact          1
3 audi         a4      2    2008     4 manual(m6) f        20    31 p     compact          1
4 audi         a4      2    2008     4 auto(av)   f        21    30 p     compact          1
5 audi         a4      2.8  1999     6 auto(l5)   f        16    26 p     compact          1
6 audi         a4      2.8  1999     6 manual(m5) f        18    26 p     compact          1

Which produces the following plot:

enter image description here

Now, let's say I would like to add a second title - based on the "small_car" variable, as follows: enter image description here

Any ideas on how to do that?

YefR
  • 369
  • 3
  • 12

0 Answers0