To create a heatmap with two values, you can use a library like D3.js. For instance, you can use the heatmap function in the heatmap.js library, which is built on top of D3.js.
To color the cells according to their values and p-values, you can use a color scale. For the first value, you can use a diverging color scale that maps positive values to blue and negative values to red. For the p-value, you can use a sequential color scale that maps low p-values to light colors and high p-values to dark colors.
Here is an example code snippet that creates a heatmap with values and p-values using the heatmap.js library and two color scales:
index.tsx1013 chars46 lines
In this example, the heatmap factory of the heatmap.js library is used to create a heatmap with the specified data and color scales. The colorScale
function is used to color the cells according to their values, and the backgroundColor
property of the returned object determines the background color of the cell. The legend
and title
properties are used to add a legend and a title to the heatmap.
After creating the heatmap, the cells
function is used to select all the cells in the heatmap, and the style
method is used to set their background color according to the p-value color scale. Note that the value
argument of the colorScale
function corresponds to the first value in the data array, while the row
and column
arguments correspond to the row and column indices of the cell in the heatmap.
gistlibby LogSnag