簡體   English   中英

R圖中的區域序列疊加

[英]Area series overlay in R plot

我有一個從簡單的3列csv文件生成的levelplot。 X列是沿軌道的距離,Y列是水深,Z列是水溫。 由於levelplot函數不知道實際的底部深度,因此它將對海床以下的值進行插值。 我想覆蓋一個填充區域系列,以掩蓋這些值並描繪海底。 我可以將沿軌道的實際底部深度添加到csv文件中,也可以創建第二個數據系列。 我不確定如何添加疊加層。 任何幫助深表感謝。

這是我的r腳本:

d<-read.csv("D:/R_plots/temp_data.csv",header=F,col.names=c("X","Y","Z")) library(latticeExtra) col.l <- colorRampPalette(c('blue', 'cyan', 'green', 'yellow', 'orange', 'red')) col.divs<-20 levelplot(Z ~ X * Y, d, cuts=50, contour=TRUE, xlab="Distance", ylab="Depth (m)", main="Temperature", col.regions=col.l, at=seq(from=0,to=6,length=col.divs), panel=panel.2dsmoother, args=list(span=0.5))

這是我目前擁有的一個例子: 在此處輸入圖片說明

這就是我想要產生的東西: 在此處輸入圖片說明

我的解決方案是使用網格功能添加xyarea面板。 測深數據是從單獨的文件加載的,並覆蓋了水平圖。

這是一個代碼示例:

data<-read.csv("D:/R_plots/temp_data.csv",
header=F,col.names=c("X","Y","Z"))
bathy<-read.csv("D:/R_plots/Bathy.csv",header=F,col.names=c("A","B"))
library(latticeExtra)
col.l <- colorRampPalette(c('blue', 'cyan', 'green', 'yellow', 
'orange', 'red'))
col.divs<-20
levelplot(Z ~ X * Y, d, cuts=50, contour=TRUE, 
         xlab="Distance (m)", ylab="Depth (m)",
         main="Temperature", col.regions=col.l,
         at=seq(from=-3,to=10,length=col.divs),
         panel=panel.2dsmoother, args=list(span=0.2))
trellis.focus("panel",1,1)
do.call("panel.xyarea",
       list(x=c(unlist(bathy["A"])), y=c(unlist(bathy["B"])),
       col="gray34",groups = NULL,origin = NULL))
trellis.unfocus()

這是示例輸出:

在此處輸入圖片說明

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM