三角プロットで「ヒートマップ」をプロットするのに十分なデータポイントを含むこのデータファイルがあります。(これは実際にはヒートマップではなく、十分なデータポイントを持つ散布図です)
library(ggtern)
library(reshape2)
N=90
trans.prob = as.matrix(read.table("./N90_p_0.350_eta_90_W12.dat",fill=TRUE))
colnames(trans.prob) = NULL
# flatten trans.prob for ternary plot
flattened.tb = melt(trans.prob,varnames = c("x","y"),value.name = "W12")
# delete rows with NA
flattened.tb = flattened.tb[complete.cases(flattened.tb),]
flattened.tb$x = (flattened.tb$x-1)/N
flattened.tb$y = (flattened.tb$y-1)/N
flattened.tb$z = 1 - flattened.tb$x - flattened.tb$y
ggtern(data = flattened.tb, aes(x=x,y=y,z=z)) +
geom_point(size=1, aes(color=W12)) +
theme_bw() +
scale_color_gradient2(low = "green", mid = "yellow", high = "red")
これが私が得たものです:
次のようなものを使用して取得したいggtern
:
私の質問は:どうすれば2番目の図のようなものを使用して取得できggtern
ますか?
編集1:ファイル名のタイプミスでごめんなさい。ファイル名を修正しました。データファイルに含まれているデータポイントが多すぎて、ここに直接貼り付けることができません。
The 2nd figure was produced by a 3rd-party Matlab package ternplot
. I want a ternary contour plot that has discrete lines rather than the heatmap in my first figure. To be more specific, I want to specify a list of contour lines such as W12=0.05,0.1,0.15,...
. I have played with geom_density_tern
and geom_interpolate_tern
for hours but still have no clue how to get what I want.
The MATLAB code is:
[HCl, Hha, cax] = terncontour(X,Y,1-X-Y,data,[0.01,0.1,0.2,0.3,0.4,0.5]);
where X,Y,1-X-Y
specify the coordinate on the plot, data
stores the values and the vector specifies the values of the contours.
WDG、私はggternにいくつかの小さな変更を加えました。これは、CRANに提出されたばかりのこのタイプのモデリングをより適切に処理するためであり、翌日かそこらで利用可能になるはずです。暫定的に、私のBitBucketアカウントからソースからダウンロードできます:https://bitbucket.org/nicholasehamilton/ggtern
とにかく、これがソースです。これはggternバージョン2.1.2から機能します。
下に(穏やかなアルファ値で)ポイントを含めたので、補間ジオメトリがどれほど代表的であるかを観察できます。
library(ggtern)
library(reshape2)
N=90
trans.prob = as.matrix(read.table("~/Downloads/N90_p_0.350_eta_90_W12.dat",fill=TRUE))
colnames(trans.prob) = NULL
# flatten trans.prob for ternary plot
flattened.tb = melt(trans.prob,varnames = c("x","y"),value.name = "W12")
# delete rows with NA
flattened.tb = flattened.tb[complete.cases(flattened.tb),]
flattened.tb$x = (flattened.tb$x-1)/N
flattened.tb$y = (flattened.tb$y-1)/N
flattened.tb$z = 1 - flattened.tb$x - flattened.tb$y
############### MODIFIED CODE BELOW ###############
#Remove the (trivially) Negative Concentrations
flattened.tb = subset(flattened.tb,z >= 0)
#Plot a series of plots in increasing polynomial degree
plots = lapply(seq(3,18,by=3),function(x){
degree = x
breaks = seq(0.025,0.575,length.out = 10)
base = ggtern(data = flattened.tb, aes(x=x,y=y,z=z)) +
geom_point(size=1, aes(color=W12),alpha=0.05) +
geom_interpolate_tern(aes(value=W12,color=..level..),
base = 'identity',method = glm,
formula = value ~ polym(x,y,degree = degree,raw=T),
n = 150, breaks = breaks) +
theme_bw() +
theme_legend_position('topleft') +
scale_color_gradient2(low = "green", mid = "yellow", high = "red",
midpoint = mean(range(flattened.tb$W12)))+
labs(title=sprintf("Polynomial Degree %s",degree))
base
})
#Arrange the plots using grid.arrange
png("~/Desktop/output.png",width=700,height=900)
grid.arrange(grobs = plots,ncol=2)
garbage <- dev.off()
これにより、次の出力が生成されます。
サンプルのMATLAB等高線図として色と方向に近い図を作成するために、次のことを試してください。
plots = lapply(seq(3,18,by=3),function(x){
degree = x
breaks = seq(0.025,0.575,length.out = 10)
base = ggtern(data = flattened.tb, aes(x=z,y=y,z=x)) +
geom_point(size=1, aes(color=W12),alpha=0.05) +
geom_interpolate_tern(aes(value=W12,color=..level..),
base = 'identity',method = glm,
formula = value ~ polym(x,y,degree = degree,raw=T),
n = 150, breaks = breaks) +
theme_bw() +
theme_legend_position('topleft') +
scale_color_gradient2(low = "darkblue", mid = "green", high = "darkred",
midpoint = mean(range(flattened.tb$W12)))+
labs(title=sprintf("Polynomial Degree %s",degree))
base
})
png("~/Desktop/output2.png",width=700,height=900)
grid.arrange(grobs = plots,ncol=2)
garbage <- dev.off()
これにより、次の出力が生成されます。
この記事はインターネットから収集されたものであり、転載の際にはソースを示してください。
侵害の場合は、連絡してください[email protected]
コメントを追加