我正在使用lat和lon数据上的kde2d(MASS)创建密度图.我想知道原始数据中哪些点在特定轮廓内.
我使用两种方法创建90%和50%的轮廓.我想知道哪些点在90%轮廓内,哪些点在50%轮廓内.90%轮廓中的点将包含50%轮廓内的所有点.最后一步是找到90%轮廓内不在50%轮廓内的点(我不一定需要这个步骤的帮助).
# bw = data of 2 cols (lat and lon) and 363 rows
# two versions to do this:
# would ideally like to use the second version (with ggplot2)
# version 1 (without ggplot2)
library(MASS)
x <- bw$lon
y <- bw$lat
dens <- kde2d(x, y, n=200)
# the contours to plot
prob <- c(0.9, 0.5)
dx <- diff(dens$x[1:2])
dy <- diff(dens$y[1:2])
sz <- sort(dens$z)
c1 <- cumsum(sz) * dx * dy
levels <- sapply(prob, function(x) {
approx(c1, …Run Code Online (Sandbox Code Playgroud) 如何在直方图/条形图上转换后添加 d3-tip / mouseover 事件?
我创建一个条形图/图:
canvas.call(tip);
var sampleBars = canvas.selectAll(".sampleBar")
.data(data)
.enter().insert("rect", ".axis")
.attr("class", "sampleBar")
.attr("x", function(d) { return x(d.x) + 1; })
.attr("y", function(d) { return y(d.y); })
.attr("width", x(data[0].dx + data[0].x) - x(data[0].x) - 1)
.attr("height", 0)
.transition()
.duration(2500)
.delay(500)
.attr("height", function(d) { return height - y(d.y); });
Run Code Online (Sandbox Code Playgroud)
我想补充一下:
sampleBars
.on('mouseover', tip.show)
.on('mouseout', tip.hide);
Run Code Online (Sandbox Code Playgroud)
这是提示:
var tip = d3.tip()
.attr('class', 'd3-tip')
.offset([-10, 0])
.html(function(d) {
return "<span style='color:white'>" + d3.round((d.y * 100))
+ "%" + "</span>" + …Run Code Online (Sandbox Code Playgroud)