Changing the position of a graph

30 Views Asked by At

enter image description here

Right now, there are only T1 and T2 variables, but I hope it keeps increasing and the graph keeps sticking to the side

But the graph keeps adding to the bottom

What should I do?

I used this code.

X <- read.table(textConnection("depth T1 T2
0 3 2
1 1 0
2 2 6
3 5 7
4 10 8
5 8 10"),header=TRUE)


library(reshape)
mX <- melt(X,id.var="depth")
names(mX)[2:3] <- c("species","abundance")
mX$fabund <- cut(mX$abundance,
                 breaks=c(-0.01,0,5,20,100),
                 labels=c("Abs","Rare","Common","Abundant"))

library(ggplot2)
p <- ggplot(mX, aes(y=depth))
p

## plot by proportion
p +
  geom_ribbon(aes(xmax = -1/2*abundance, xmin = +1/2*abundance))+
  facet_grid(species ~ .)+
  coord_fixed(ratio = 2)+
  theme_bw()+
  xlim(-10,10)+
  ylim(5,0)+
  xlab("Abundance (inds./㎥)")+
  ylab("Depth (m)")
1

There are 1 best solutions below

0
On BEST ANSWER

I would suggest using facet_wrap() instead of facet_grid() and specify that you only want one row of plots using nrow=1

ggplot(mX, aes(y=depth)) +
  geom_ribbon(aes(xmax = -1/2*abundance, xmin = +1/2*abundance))+
  facet_wrap(~species,nrow=1)+
  coord_fixed(ratio = 2)+
  theme_bw()+
  xlim(-10,10)+
  ylim(5,0)+
  xlab("Abundance (inds./㎥)")+
  ylab("Depth (m)")

enter image description here