This is still not possible in ggplot2
, but it is possible in ggvis
, which combines the ggplot2
grammer with dplyr
pipelines. Just use the add_axis
function to put the axis at the top.
# sample data
N <- 20
df <- data.frame(conc = seq(0, N),
depth = runif(N+1, 0, 20),
stn = rep(1:4, length=N+1))
# ggplot version
require(ggplot2)
p <- ggplot(df, aes(x= conc, y=depth, group=factor(stn), color=factor(stn)))+
geom_point(shape=1)+
geom_path(alpha=0.5)+
scale_y_reverse(limits=(c(20,0)), expand=c(0,0))+
scale_x_continuous(expand=c(0,0))
p
# ggvis version
require(ggvis)
df %>% transform(stn = factor(stn)) %>%
ggvis(x = ~conc, y = ~depth, stroke = ~stn) %>%
layer_points(shape := "circle", fill := "white") %>%
layer_lines(opacity := 0.5) %>%
scale_numeric("y", reverse=TRUE, domain=c(0,20), expand=c(0,0)) %>%
scale_numeric("x", expand=c(0,0)) %>%
add_axis("x", orient = "top")