抬起头,我是R菜鸟,请裸露!
我正在尝试使用密度热图来确定数据点最多的区域。
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)
很抱歉如此愚蠢,这是我的新手,感谢您从此网站中学到很多东西!
答案 0 :(得分:0)
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
,您应该得到以下图解: