2

I am trying to fill the space between two curves, however geom_ribbon uses varying y values rather than x values. My y axis is depth so I don't really want to swap the axes over. Is there any way to do this? Here is a sample of my dataset:

Statsrep <- structure(list(Depth = c(34L, 74L, 114L, 164L, 204L, 264L, 304L, 344L, 384L, 424L, 
464L, 504L, 554L), Min = c(2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2), Max = c(38, 105, 86, 44, 68, 
155, 160, 68, 120, 1670, 178, 110, 84), Average = c(5.64, 12.08, 17.42, 6.5, 11.59, 11.09, 10.1, 
9.09, 8.08, 38.96, 15.94, 6.53, 13.21), Mode = c(2,2,3,2,6,2,2,2,2,2,2,2,2)), .Names = 
c("Depth", "Min", "Max", "Average", "Mode"), row.names = c(1L, 2L, 3L, 4L, 5L, 6L, 7L, 8L, 9L, 
10L, 11L, 12L, 13L), class = "data.frame")
Statsrep

The code i am currently using is:

Statsrep <- read.csv(file="filename.csv", header=TRUE, sep=" ")
p1 <- ggplot(data = Statsrep, aes(xmin=Min, xmax=Max, y=Depth)) +
geom_ribbon(aes(fill="#CCCCCC"))
p1 <- p1 + coord_trans(x = "log10") + 
scale_x_continuous(breaks=c(1, 10, 100, 1000, 1500)) +
ylim(600,0)
p1 <- p1 + layer(geom = "path")
p1 + xlab("GRAINSIZE / mm")
p1 + ylab("DEPTH / m")

Also, I want to customise my log x axis so that there are 1, 10, 100, 1000 labels showing and equally spaced, similar to log graph paper. This code only shows 100, 1000, 1500 that are bunched up toward the right of the axis. Is there any way to format the axis like this? Thanks for any help in advance. Holly

Holly Elliott
  • 103
  • 3
  • 10
  • Could you please make it reproducible? http://stackoverflow.com/questions/5963269/how-to-make-a-great-r-reproducible-example – Luciano Selzer Aug 16 '12 at 17:29
  • My apologies. I hope that makes it a little easier? I wasn't sure how to call the data from the list so you may have to save it to a csv file - sorry.... – Holly Elliott Aug 16 '12 at 18:36
  • That has definitely solved the issue thank you both so much!!! You have just put an end to countless hours of frustration. Holly – Holly Elliott Aug 17 '12 at 12:21

2 Answers2

2

This may help you get started, though I'm still not entirely sure what you're after:

p1 <- ggplot(data = Statsrep, aes(ymin=Min, ymax=Max, x=Depth,y = Average)) +
        geom_ribbon(alpha = 0.5) + 
        geom_line(aes(group = 1)) +
        scale_y_log10() + 
        coord_flip()

enter image description here

joran
  • 169,992
  • 32
  • 429
  • 468
2

I guess she wants the depth to go downwards

  ggplot(data = Statsrep, aes(ymin=Min, ymax=Max, x=Depth, y = Average)) +
  geom_ribbon(alpha = 0.5) + 
  geom_line(aes(group = 1)) +
  scale_y_log10("GRAINSIZE / mm", breaks=c(1, 10, 100, 1000)) +
  scale_x_reverse("DEPTH / m", limits = c(600,0)) + 
  coord_flip()

The graph looks diferent because I'm using a custom theme for the whole session.

enter image description here

Luciano Selzer
  • 9,806
  • 3
  • 42
  • 40