我有一个关于使用面的线图的奇怪结果的问题。
我有不同深度(=压力)的水数据测量。数据以表格形式出现:
Pressure Temperature pH
0 30 8.1
1 28 8.0
我“融化”了这些数据以产生:
Pressure variable value
0 Temperature 30
1 Temperature 30
0 pH 8.1
1 pH 8.0
等等。我现在绘制这个:
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())
它有点工作,除了线图的某些部分填充了纯色。我不知道为什么,尤其是因为如果我将 x 换成 y 并使用“变量 ~”,它就可以正常工作。作为 facet_grid 公式。
最佳答案
注意geom_line
之间的区别和 geom_path
应用于相同的数据。
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()
注意
df
中的顺序数据框。 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
按观察顺序绘制。geom_line
按 x 值的顺序绘制。当 x 值更接近时,效果更明显。
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()
关于r - ggplot2 多面线图的线条区域用纯色填充,为什么?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/10764418/