r - ggplot2 多面线图的线条区域用纯色填充,为什么?

标签 r ggplot2

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

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 公式。
weird plot

最佳答案

注意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() 

enter image description here

注意 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()

enter image description here

关于r - ggplot2 多面线图的线条区域用纯色填充,为什么?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/10764418/

相关文章:

r - 以自定义比例和间距将 ggplots 排列在一起

r - 如何在 lmer 或 glmer 中预测和绘制非线性变化斜率?

r - cbind 列表中的特定列(没有 dplyr 包)

r - 使用 shinyapps.io 检测语言环境时出错

r - 如何根据以前的方 block 递归创建方 block ?

r - 调整 ggplot2 中的 legend.title、legend.text 和图例颜色

r - 从共享通用 aes 名称的两层生成的图例中删除一个 aes

r - 不使用 data.frame 的数值透明查找表?

r - 使用计数将长格式转换为宽格式的简单方法

r - 从头开始查找向量重叠