抬起头来,我是一个R noob,所以请光顾!
我正在尝试使用密度热图来识别大多数数据点所在的区域。
Here is what the plot looks like
到目前为止,我必须添加到此代码中的哪些内容(我明显列出了较少的数据点)才能应用此“热图”?
par(mfrow=c(1, 2), mar=rep(0.3, 4))
TernaryPlot(atip = "Red", btip = "Green", ctip = "Blue", alab="Redder\u2192", blab="Greener \u2192", clab="Bluer \u2190",
point='Up', lab.cex=0.8, grid.minor.lines = 0,
grid.lty='solid', col=rgb(0.9,0.9,0.9), grid.col='White',
axis.col=rgb(0, 0, 0), ticks.col=rgb(0, 0, 0),
padding=0.08)
data_points <- list(
c(0.89,0.88,0.78),
c(0.98,0.96,0.92),
c(0.6,0.52,0.28),
c(0.88,0.9,0.85),
c(0.96,0.87,0.6),
c(0.63,0.53,0.29),
c(0.92,0.85,0.09),
c(0.84,0.87,0.87),
c(0.93,0.88,0.88),
c(0.98,0.76,0.71)
)
AddToTernary(points, data_points, bg=vapply(data_points, function (x) rgb(x[1], x[2], x[3], 1, maxColorValue=1), character(1)), pch=25, cex=0.8)
AddToTernary(text, data_points, names(data_points), cex=0.8, font=2)
很抱歉这么傻,非常新的一切,感谢这个网站!
来自TernaryPlot
包的Ternary
函数创建并设置了一个空白的三元图。如果您想显示数据点,则需要使用TernaryPoints
函数:
TernaryPlot(atip = "Red", btip = "Green", ctip = "Blue", alab="Redder\u2192", blab="Greener \u2192", clab="Bluer \u2190",
point='Up', lab.cex=0.8, grid.minor.lines = 0,
grid.lty='solid', col=rgb(0.9,0.9,0.9), grid.col='White',
axis.col=rgb(0, 0, 0), ticks.col=rgb(0, 0, 0),
padding=0.08)
TernaryPoints(data_points)
你会得到以下情节:
另一个选择是使用vcd
库:
library(vcd)
# convert data points into a matrix
data_points = matrix(unlist(data_points), ncol=3, byrow=T)
ternaryplot(x=data_points)
使用vcd
,你应该得到以下情节: