如何在geom_raster plot

时间:2017-02-23 07:05:09

标签: r ggplot2 geom-raster

我正在尝试使用geom_raster和geom_line在R中制作以下图像(我使用这些中的每一个单独制作并在顶部照片购物)。

x是时间(这里是天), y是深度(m), 颜色是温度(C)

Figure I want

背景颜色是每个十米深度纸槽的平均温度,不随x变化。 该线是每两分钟记录的深度读数。

我有办法在ggplot中做到这一点吗?

我的数据框架结构和获取这些图的代码很简单:

 Unique.days depthbins temperature Unique.point  ActualDepth
  119         5        29.34            1        61.9
  119         15       29.10            2        52.8
  119         25       28.90            3        53.8
  119         35       28.45            4        52.8
  119         45       27.23            5        60.2
  119         185      21.57            19       10
  119         195      21.38            20       15.1
  119         5        29.34            21       20.1
  119         15       29.1             22       15.2

温度是每个深度仓的平均值,这些行每整个数据集重复20行。 ActualDepth是整个数据集中不同的跟踪。

(1)对于栅格

代码:

ggplot(data = test1, aes(x = Unique.days, y = depthbins)) +
  geom_raster(aes(fill = temperature), interpolate = TRUE) +
  scale_y_reverse()

(2)对于geom_line

CODE:

ggplot(data = test1, aes(x = Unique.point, y = ActualDepth)) +
  geom_line(data = test1, aes(x = Unique.point, y = ActualDepth)) +
  scale_y_reverse() +
  theme_bw()

当我尝试将它们组合在一起时,我无法获得正确的比例。 例如

ggplot(data = test1, aes(x = Unique.days, y = DepthBins)) +
  geom_raster(aes(fill = temperature), interpolate = TRUE) +
  scale_y_reverse() +
  geom_line(data = test1,
            aes(x = Unique.days, y = ActualDepth),
            col = 'white')

结果:

geom_line off scale

色彩现在并不重要,但我希望深度变化是显而易见的。

任何帮助将不胜感激!

0 个答案:

没有答案
相关问题