1

I'm making a facet_wrap panel plot in ggplot2. with flip x- and y-axis, and a reverse of the x-axis.

example dataset:

   Position Depth   Var   Value
    S07     1000    SFA   0.5885938
    S07     1000    MFA   0.6228922
    S07     1000    DFA   0.6276554
    S07     120     SFA   0.7342712
    S07     400     MFA   0.379946
    S07     400     DFA   0.6565114
    S07     120     SFA   0.7330876
    S07     25      SFA   0.7505527
    S07     120     DFA   0.461091
    S07     25      SFA   0.6202075
    S07     400     DFA   0.427386
    S07     25      SFA   0.4705119
    S08     200     SFA   0.6237663
    S08     200     SFA   0.6275681
    S08     400     MFA   0.4675334
    S08     25      SFA   0.6647344
    S08     1000    DFA   0.4452225
    S08     200     SFA   0.3845796
    S08     400     MFA   0.4521598
    S08     400     SFA   0.5158677
    S08     25      DFA   0.4556605
    S08     25      SFA   0.5381858
    S08     1000    DFA   0.434988
    S08     1000    MFA   0.4554283
    S09     200     SFA   0.6135895
    S09     25      MFA   0.7472166
    S09     400     SFA   0.4461884
    S09     1000    DFA   0.4197083
    ...     ...     ...   ...

The codes I'm using,

 library(ggplot2)
 library(cowplot)

ggplot(df, aes(x=x, y=y, fill=Position))+
  geom_point()+
  geom_line(aes(group=Position)+
  coord_flip() +

  scale_x_reverse(breaks=c(25, 120,200, 400, 1000))+
  scale_y_continuous(position = "top")+

  facet_wrap(~var, nrow=2, scales='free')+

  theme(strip.background = element_blank(),
    panel.border = element_blank())

one panel of the figure I got is the left one: enter image description here

How could I switch the position of Panel title "SFA" and axis, and connect the two axes, like the right figure?

Community
  • 1
  • 1
Jellz
  • 435
  • 1
  • 7
  • 14
  • 2
    Could you provide a data sample with dput()? I think that playing around with scales="free" while forcing common limits may solve this. – Luke Hayden Apr 25 '18 at 08:45
  • Please provide a reproducible example like @LukeHayden suggests . This will give people who want to help you something to work with and to test. You can read about it **[here](https://stackoverflow.com/questions/5963269/how-to-make-a-great-r-reproducible-example)**. – KoenV Apr 25 '18 at 09:00

0 Answers0