ggplot2 faceted line plot has areas of the line filled with solid color, why?
ggplot2, r
Solution
Note the difference between `geom_line` and `geom_path` applied to the same data.
library(ggplot2)
x = c(seq(1, 10, 1), seq(10, 1, -1))
y = seq(0, 19, 1)
df = data.frame(x, y)
ggplot(df, aes(x, y)) + geom_line()
ggplot(df, aes(x, y)) + geom_path()
Note the order in the `df` data frame.
x y
1 1 0
2 2 1
3 3 2
4 4 3
5 5 4
6 6 5
7 7 6
8 8 7
9 9 8
10 10 9
11 10 10
12 9 11
13 8 12
14 7 13
15 6 14
16 5 15
17 4 16
18 3 17
19 2 18
20 1 19
`geom_path` plots in order of the observations.
`geom_line` plots in order of x values.
The effect is more marked when the x values are closer together.
x = c(seq(1, 10, .01), seq(10, 1, -.01))
y = seq(.99, 19, .01)
df = data.frame(x, y)
ggplot(df, aes(x, y)) + geom_line()
ggplot(df, aes(x, y)) + geom_path()
Problem
I have a question regarding a weird result for a line plot that uses facets. I have water data masurements for different depth (=pressures). The data comes as a table as such: ``` Pressure Temperature pH 0 30 8.1 1 28 8.0 ``` I "melt" this data to yield: ``` Pressure variable value 0 Temperature 30 1 Temperature 30 0 pH 8.1 1 pH 8.0 ``` and so on. I now plot this: ``` ggplot(data.m.df, aes(x=value, y=Pressure)) + facet_grid(.~variable, scale = "free") + scale_y_reverse() + geom_line() + opts(axis.title.x=theme_blank()) ``` It kinda works, except there are parts of the line plot that get filled with solid color. I have no idea why, especially because it works just fine if I exchange x for y and use "variable ~ ." as the facet_grid formula.