5

我有一个关于使用构面的线图的奇怪结果的问题。我有不同深度(=压力)的水数据测量。数据以表格形式出现:

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 公式。 诡异的情节

4

1 回答 1

10

请注意应用于相同数据之间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()

在此处输入图像描述

于 2012-05-26T09:01:48.293 回答