Reputation: 3471
Consider
data <- data.frame(A=runif(10), B=runif(10), Height=c(1:10))
library(reshape)
melted <- melt(data, id.vars="Height")
library(ggplot2)
ggplot(melted, aes(value, Height)) +
geom_point()+
scale_y_reverse(breaks=c(1:10)) +
facet_wrap(~variable,scale="free_x")+
geom_line(aes(group=variable))
geom_line is connecting the dots along the x-axis, but i would like it to connect the dots on the y-scale, to show the Height profile of my data. I was trying coord_flip()
and exchange the aes(x,y)
arguments, but that doesnt work with the scale argument in facet_wrap.
Side question: In
scale_y_reverse(breaks=c(1:10)) +
i cannot exchange c(1:10)
with Height
, as the object is not found. This is odd, as it worked in my real life data.
Upvotes: 3
Views: 3208
Reputation: 15425
geom_line
joins lines up from the minimum x to maximum. In order to get the lines drawn in a different order, you need to use geom_path
.
ggplot(melted, aes(value, Height)) +
geom_point()+
scale_y_reverse(breaks=c(1:10)) +
facet_wrap(~variable,scale="free_x")+
geom_path(aes(group=variable))
Upvotes: 2