气泡图是一种图表,我们可以绘制3个值。使用气泡的直径显示X轴中的一个值,Y轴中的一个值和第三个值。它非常类似于一个表格,其中的值用气泡的直径表示。
我用传奇,文字和注释做了一个散点图。但是,当我单击传说文本和与气泡相关的注释时。请检查以下代码。 const getannotati ...
const getAnnotations = () => { if (totalRecords <= 10) { const annotations: any[] = []; const placedPositions: { x: number; y: number }[] = []; const groupedData = new Map<string, { storeLabels: string[], x: number, y: number, z: number }>(); // Group data by total_sales and spearman_correlation data.forEach((item) => { const storeLabel = item[firstColumnFieldName] || "Unknown Store"; const key = `${item.total_sales}-${item.spearman_correlation}`; if (!groupedData.has(key)) { groupedData.set(key, { storeLabels: [], x: item.total_sales, y: item.spearman_correlation, z: item.max_sales }); } groupedData.get(key)!.storeLabels.push(storeLabel); }); // Alternating offsets for y (up and down) let isPositiveYOffset = true; groupedData.forEach(({ storeLabels, x, y, z }) => { // Only include annotations where spearman_correlation is greater than 0.2 or less than -0.2 if (y <= 0.5 && y >= -0.5) return; // Skip if correlation is between -0.2 and 0.2 const combinedLabel = storeLabels.join(", <br>"); // Combine store names with commas const isShortLabel = combinedLabel.length <= 3; // Check if label is short // Calculate bubble size based on total_sales (or another metric if necessary) const bubbleSize = calculateBubbleSize(y, totalRecords, x, z, allLessThanOrEqualZero); // Check if label can fit inside the bubble const labelFitsInsideBubble = !isLabelTooBig(combinedLabel, bubbleSize); // Alternate between positive and negative y offsets for annotation placement const yOffset = isPositiveYOffset ? 30 : -30; // Switch between positive and negative offsets for next annotation isPositiveYOffset = !isPositiveYOffset; // Function to check if an annotation overlaps with either an existing bubble or annotation const isOverlapping = (x: number, y: number, bubbleSize: number) => { // Check if it overlaps with other annotations const annotationOverlap = placedPositions.some(pos => { const distance = calculateDistance(pos.x, pos.y, x, y); return distance < bubbleSize * 0.8; // Adjust threshold as necessary for annotations }); // Check if it overlaps with any bubbles const bubbleOverlap = placedPositions.some(pos => { const distance = calculateDistance(pos.x, pos.y, x, y); return distance < bubbleSize; // Adjust threshold for bubbles }); // If either overlaps, return true return annotationOverlap || bubbleOverlap; }; // Apply the y offset and check for overlap with bubbles and annotations let currentX = x; // Keep the x position same for each annotation let currentY = y + yOffset; // Apply y offset (up/down) // If it overlaps with existing bubbles or annotations, skip this annotation if (isOverlapping(currentX, currentY, bubbleSize)) { return; } // No overlap, so add the position placedPositions.push({ x: currentX, y: currentY }); // Add the annotation to the list annotations.push({ x: x, y: y, text: `<b>${combinedLabel}</b>`, // Display combined label showarrow: !labelFitsInsideBubble, // Show arrow if label is outside arrowhead: 1, arrowwidth: 2, ax: labelFitsInsideBubble ? 10 : 30, // Offset if label is too big ay: labelFitsInsideBubble ? yOffset : -yOffset, // Adjust vertical offset if label is too big font: { size: labelFitsInsideBubble ? 12 : 10, color: labelFitsInsideBubble ? "white" : "black", weight: "800" }, bgcolor: labelFitsInsideBubble ? "transparent" : "white", // Transparent if label fits bordercolor: labelFitsInsideBubble ? "transparent" : "black", borderradius: 10, // Rounded corners xanchor: isShortLabel ? "center" : undefined, yanchor: isShortLabel ? "middle" : undefined, arrowcolor: "black", // Set arrow color }); }); return annotations; } return []; };
我一直在探索R中的ggplot和scale_size。 但是,我不知道如何指定中断次数或范围。 我想将计数数据分成 5 个类别,最大...
我正在使用 highcharts 中的气泡图。如果我将鼠标悬停在气泡上,它会显示工具提示信息。其中,“糖摄入量”值出现,中间有一个空格来代表面额...
名称经纬度 XX -20.6544 150.9149 这是我的数据的样子,有超过 1000 个条目 我尝试过的代码如下。 # 图书馆 图书馆(传单) # 加载示例数据(斐济地球邮政编码...
我想了解美国联邦政府正在开发哪些机器学习应用。 联邦政府维护包含合同的 FedBizOps 网站。 ...
React 中的 D3 在从 useState 更新数据时出现问题
我正在使用 React 并开始使用 D3 创建气泡图。 我们的主要思想是我们有一个 useState ,它随着数据的时间而变化。 数据可能会发生三种情况:新的、...
我使用metafor包在R中进行了元回归。 res.quad <- rma(mix.minor.1.1_estimates, sei = mix.minor.1.1_errors, mods = ~ poly(minperc, degree=2, raw=TRUE), data=meta2) res.qu...
我创建了一个气泡图,底部有一张地理地图,上面以气泡的形式表示点。这些点具有纬度经度信息,借助这些信息,他们可以获得
我是编码新手,所以我希望我提供回答这个问题所需的所有信息!我正在使用 R 中的元包进行元回归,并使用 bubble 函数来绘制它。我有 173
我有两个包含相同行但不同列的数据集,除了它们之间共有的一列(订单列) 我想创建如图所示的气泡图 例子...
如何更改 R Highcharter 中气泡图例的范围和颜色?
我正在 R 中使用 Highcharter 制作气泡宪章。但是我还没有设法修改气泡大小图例的颜色或图例中显示的气泡大小的范围,即我...
我想改变图中气泡的颜色 ggplot(总和长度, aes(x=vb_width, y=斜率, 大小=长度)) + geom_point(alpha=0.5)+ 主题_经典() + ylab("坡度类别...
我用 Python Plotly 创建了一个气泡图。在下面的示例中,气泡的大小代表不同国家的人口规模。我想添加气泡大小...
使用 packcircles 创建气泡图我想要圆形而不是椭圆形加上图例 ggplot
我想使用 packcircles 包和 ggplot 创建一个图表。并用我的导出它 我在这种情况下使用的打印设备“ragg”。 我有三个问题 我想要转换的圈子...
我有一组数字序列,保存在二维列表中。列表中的每个元素都是不同长度的子列表,例如 1-10 范围内的数字。像这样: Lst = [[1,3,4,4,4,5],[2,7,2,3],[...
我遇到过许多与散点图/群图非常相似的图(页尾),它们抖动 y 轴以避免重叠的点/气泡。 我怎样才能得到 y 值(ide...
MatPlotLib 新手在这里! 下面的 Pandas DataFrame 是真实 DataFrame 的简化版,它有更多的年份和更多的事件: df = pd.DataFrame({ ‘年份’: [2016, 2017, 2018, 2019, 20...
我目前正在尝试在 Matplotlib 中制作气泡图,其中气泡不重叠,因此将圆圈/气泡包装在图表中,大约像这样。 我认为可能有效的方法: 普洛...
我看到excel中生成了一个图,我想知道R是否也可以做到。 这张图片本质上是一个交叉表的可视化,将一周中的几天与该日期上的首选膳食进行比较......
我需要帮助在每个面网格内分布气泡并删除下图中每个面网格内的网格线。 图 <- ggplot(patog1, aes(x = Prevalence, y = Microorganism...