holtzy / d3-graph-gallery Goto Github PK
View Code? Open in Web Editor NEWA collection of simple graphics made with D3.js
Home Page: https://www.d3-graph-gallery.com
License: MIT License
A collection of simple graphics made with D3.js
Home Page: https://www.d3-graph-gallery.com
License: MIT License
I don't think this translate is needed on the zoom and pan example since the SVG element is already translated and the pointer event rect is relative to that.
Hi! Love the website and thanks for the amazing charts. I just used the stacked grouped circular barplot (https://www.r-graph-gallery.com/299-circular-stacked-barplot.html), and needed to order the bars like you did in the regular one (https://www.r-graph-gallery.com/297-circular-barplot-with-groups.html), so after some tinkering I got it to work by replacing this line:
data <- data %>% arrange(group, individual)
with this line:
data <-data %>% group_by(group, individual) %>% mutate(sumValue=sum(value, na.rm = T)) %>% arrange(group, sumValue, individual) %>% ungroup()
Just thought I'd share back if you'd like to add it as an optional feature.
Thanks again for your work!
The angle of the text isn't calculating correctly.
Using ruby 2.7.3 Rails 6.1.3
I am using d3 but it throws the below error on console -
TypeError: setting getter-only property "format" using
Ie https://d3js.org/d3.v4.min.js:2
https://d3js.org/d3.v4.min.js:2
https://d3js.org/d3.v4.min.js:2
https://d3js.org/d3.v4.min.js:2
On the view page, I have added the below code -
<script src="https://d3js.org/d3.v4.min.js">
</script>
<%= javascript_pack_tag "home/index" %>*
Below line added app/javascript/packs/application.js -
import * as d3 from "d3"
window.d3 = d3
Please give suggestions on these.
I am trying to execute these examples I found from: https://www.r-graph-gallery.com/311-add-labels-to-hierarchical-edge-bundling.html to R directly:
#========================================= Part A Without Labels ===============================================
# Libraries
library(ggraph)
library(igraph)
library(tidyverse)
library(RColorBrewer)
# create a data frame giving the hierarchical structure of your individuals
set.seed(1234)
d1 <- data.frame(from="origin", to=paste("group", seq(1,10), sep=""))
d2 <- data.frame(from=rep(d1$to, each=10), to=paste("subgroup", seq(1,100), sep="_"))
edges <- rbind(d1, d2)
# create a dataframe with connection between leaves (individuals)
all_leaves <- paste("subgroup", seq(1,100), sep="_")
connect <- rbind(
data.frame( from=sample(all_leaves, 100, replace=T) , to=sample(all_leaves, 100, replace=T)),
data.frame( from=sample(head(all_leaves), 30, replace=T) , to=sample( tail(all_leaves), 30, replace=T)),
data.frame( from=sample(all_leaves[25:30], 30, replace=T) , to=sample( all_leaves[55:60], 30, replace=T)),
data.frame( from=sample(all_leaves[75:80], 30, replace=T) , to=sample( all_leaves[55:60], 30, replace=T)) )
connect$value <- runif(nrow(connect))
# create a vertices data.frame. One line per object of our hierarchy
vertices <- data.frame(
name = unique(c(as.character(edges$from), as.character(edges$to))) ,
value = runif(111)
)
# Let's add a column with the group of each name. It will be useful later to color points
vertices$group <- edges$from[ match( vertices$name, edges$to ) ]
#======================================= Part B Create with Labels ===============================================
#Let's add information concerning the label we are going to add: angle, horizontal adjustement and potential flip
#calculate the ANGLE of the labels
vertices$id <- NA
myleaves <- which(is.na( match(vertices$name, edges$from) ))
nleaves <- length(myleaves)
vertices$id[myleaves] <- seq(1:nleaves)
vertices$angle <- 90 - 360 * vertices$id / nleaves
# calculate the alignment of labels: right or left
# If I am on the left part of the plot, my labels have currently an angle < -90
vertices$hjust <- ifelse(vertices$angle < -90, 1, 0)
# flip angle BY to make them readable
vertices$angle <- ifelse(vertices$angle < -90, vertices$angle+180, vertices$angle)
#====================================== Part C Plot the Labels ==================================================
# Create a graph object
mygraph <- igraph::graph_from_data_frame( edges, vertices=vertices )
# The connection object must refer to the ids of the leaves:
from <- match( connect$from, vertices$name)
to <- match( connect$to, vertices$name)
x11()
# Basic usual argument
ggraph(mygraph, layout = 'dendrogram', circular = TRUE) +
geom_node_point(aes(filter = leaf, x = x*1.05, y=y*1.05)) +
geom_conn_bundle(data = get_con(from = from, to = to), alpha=0.2, colour="skyblue", width=0.9) +
geom_node_text(aes(x = x*1.2, y=y*1.2, filter = leaf, label=name,
angle = angle, hjust=hjust), size=2, alpha=1) +
theme_void() +
theme(
legend.position="none",
plot.margin=unit(c(0,0,0,0),"cm"),
) +
expand_limits(x = c(-1.2, 1.2), y = c(-1.2, 1.2))
And I got this results like this (which the order of labeling seems off)
How can I make it exactly as the examples provide?
See Mark Philips email
I just noticed that the examples do not work with the newest d3.js release (v5). It took me forever to find out that this happens because the data loading with d3.csv()
and d3.json()
now supports promise based syntax. So instead of writing
<script src="https://d3js.org/d3.v4.js"></script>
<script>
d3.csv(url, function(data) {
// ...
});
</script>
You can write
<script src="https://d3js.org/d3.v5.min.js"></script>
<script>
d3.csv(url).then(function(data) {
// ...
}).catch(function(error) => {
console.log(error);
});
</script>
Thought i share it here maybe worth updating all the examples? If you want me to do it let me know, I could invest some time. Really thank you for providing this great page, really helpful.
Hi Yan
I am using your D3 gallery, it is really useful for my D3 learning so thanks for putting it together.
I noticed a small typo in this link and heading, I think it should be spelt "Responsiveness"
https://www.d3-graph-gallery.com/graph/custom_responsive.html
Responsivness in d3.js
Hi Yan,
Great website. I was trying to use your code to create a circular plot as in "https://www.r-graph-gallery.com/311-add-labels-to-hierarchical-edge-bundling.html". But your code is ending with the warning "Removed 1 rows containing missing values (geom_edge_path)." without creating the plot. I am not sure where the problem is. Can you please help?
Best,
Arkaprava
Hi Yan,
You don’t know me but I was just looking at this example:
https://www.d3-graph-gallery.com/graph/boxplot_basic.html
I am pretty sure that the ends of the boxplot whiskers are generally calculated differently in the statistics profession. I recall that the top whisker is at the 90th percentile and the bottom whisker represents the 10th percentile. In the D3 example these values seem a bit arbitrary and not related to the data.
So I’d recommend this code instead
var min = d3.quantile(data_sorted, .1);
var max = d3.quantile(data_sorted, .9);
Just some friendly feedback.
Otherwise the graphs and code examples are really helpful and a great resource.
Thanks.
Ross.
How to implement the line_change_data graph to be suitable for a bar chart to change data?
` // Create a update selection: bind to the new data
var u = svg.selectAll(".lineTest")
.data([data], function(d){ return d.ser1 });
// Updata the line
u
.enter()
.append("path")
.attr("class","lineTest")
.merge(u)
.transition()
.duration(3000)
.attr("d", d3.line()
.x(function(d) { return x(d.ser1); })
.y(function(d) { return y(d.ser2); }))
.attr("fill", "none")
.attr("stroke", "steelblue")
.attr("stroke-width", 2.5)`
In https://d3-graph-gallery.com/graph/line_several_group.html
"d3.nest" no longer exists. This should be re-written to use d3.group.
P.S. note at the bottom says "fill a bug" instead of "file a bug"
Great website consolidating web charting libraries.
However, the licensing information is also important.
For example, I know d3js is BSD license, however, R falls under GPL license.
As for the examples, a lot of them includes additionally third party libraries which may fall under yet another licensing.
Hi,
The chart created using the code on this page (https://www.r-graph-gallery.com/297-circular-barplot-with-groups.html) does not create the spaces between the groups. The reason is that data$group has a character class but we need a factor class to create the levels and then create the empty matrix of NAs.
The issue can be solved by adding as.factor() with every data$group.
Thanks
Hi, Yan,
Just a quick note to say that I found your work on zooming at https://d3-graph-gallery.com/graph/interactivity_zoom.html to be a very useful starting point for a hands-on review of D3's imperative way of implementing zoom-and-pan with axes.
I need to review that topic in some depth before trying to port an interactive D3 visualization from a working React app to Svelte with its declarative approach. (Tom Février's video is useful in this regard, but I still have some work ahead of me.)
FYI, I made a few small changes to your code only tohelp me better understand the "moving parts":
I used only a few data points...
// Add circles
scatter
.selectAll("circle")
.data([data[4], data[27], data[73]])
I styled the scatter's with an outline -- a tip I found on SO here (@gavgrif's answer)...
let scatter = SVG.append('g')
.attr("clip-path", "url(#clip)")
.style('outline', '2px solid red')
...and gave the 'invisible' some visibility with an outline and a fill...
SVG.append("rect")
.attr("width", width)
.attr("height", height)
.style("fill", "#f5f5dc83")
.style('outline', '2px solid rebeccapurple')
.style("pointer-events", "all")
//.attr('transform', 'translate(' + margin.left + ',' + margin.top + ')')
.call(zoom);
(A screenshot is attached.)
Those additions led me to comment out the transform attr of the invisible (see above) so that it fit the svg's content area. (Otherwise, I noticed that attempting to pan or zoom when near the y-axis -- i.e., within the chart content but outside of the invisible -- failed.)
I also chained translateExtent() to the zoom behavior function to 'lock' the limits of the x- and y-scale domain arrays (which works as expected after setting the min scaleExtent to '1'.
let zoom = d3.zoom()
.scaleExtent([1, 20])
.extent([[0, 0], [width, height]])
.translateExtent([[0, 0], [width, height]])
.on("zoom", updateChart);
Overall: Thanks again, and Regards,
--Nick/
Hi Yan,
Thank You for the example:
https://www.d3-graph-gallery.com/graph/custom_responsive.html
It helped me to learn d3 chart responsiveness.
I have one problem though. I have to resize the page, only then the
graph fits into parent div. When the page loads, or when I load it after
zooming, the graph is oversized and stretches outside parent div.
Could You advise?
Kind,
Damian
Hi, great set of D3 examples, thank you.
A minor bug when trying the most basic circular-barplot. As part of adding the bars, you should also transform the origin of the appended group. Otherwise only a quarter of the plot will be shown. The revised code:
svg
.append('g')
// => this next line needs to be added so that the entire plot is centered in the svg element
.attr('transform', `translate(${width / 2},${height / 2 + 100})`)
.selectAll('path')
.data(data)
.join('path')
.attr('fill', '#69b3a2')
.attr(
'd',
d3
.arc() // imagine your doing a part of a donut plot
.innerRadius(innerRadius)
.outerRadius(d => y(d['Value']))
.startAngle(d => x(d.Country))
.endAngle(d => x(d.Country) + x.bandwidth())
.padAngle(0.01)
.padRadius(innerRadius),
);
Thanks again, your gallery is very helpful.
On the page https://www.d3-graph-gallery.com/graph/pie_basic.html I think the code v6 should be : .attr('fill', function(d){ return(color(d.data)) })
and not .attr('fill', function(d){ return(color(d.data[1])) })
.
Otherwise, it isn't identical to the code for v4.
Example with different values : (messed up colors if numbers are similar)
v4 - https://jsfiddle.net/jnve0fb9/
v6 - https://jsfiddle.net/z2jcwf3x/
I used your page for migrating to v6, but this details got me confused for a while.
Hi, I love your repo!
Just for a report, the first two samples in the Building tooltips with d3.js not working nighter in safari nor chome.
Expected result: seeing a tooltip when the mouse hovers the circle
Actual result: there is no tooltip
Thanks.
hi! i don't succeed in plotting my charts and i don't know why, I append my code below, the problem is both on linechart.js that plot only vertical lines and scatter.js that goes in error. The other files (like map or pca ) are ok. pls help me, i think the problem is the db that has a lot of missing values
Hi,
there seems to be an argument missing in the following code, causing the labels to not be aligned correctly. The problem is in the final theme, but I cannot figure out the solution.
ggraph(mygraph, layout = 'dendrogram', circular = TRUE) +
geom_node_point(aes(filter = leaf, x = x1.05, y=y1.05)) +
geom_conn_bundle(data = get_con(from = from, to = to), alpha=0.2, colour="skyblue", width=0.9) +
geom_node_text(aes(x = x1.1, y=y1.1, filter = leaf, label=name, angle = angle, hjust=hjust), size=1.5, alpha=1) +
theme_void() +
theme(
legend.position="none",
plot.margin=unit(c(0,0,0,0),"cm"),
) +
expand_limits(x = c(-1.2, 1.2), y = c(-1.2, 1.2))
I need to add a default fill to the circle or the button to change it won't work.
As iam new to javascript , iam not being able to draw force directed graph from my json file. Please help me to draw the graph with node size according to the size given in the node description and color according to the pagerank
Here iam attaching the json file :
{ "directed": false, "multigraph": false, "graph": { "node_default": {}, "edge_default": {} }, "nodes": [ { "name": "leuT", "pagerank": 0.008401503126648335, "size": 13.460111406714873, "id": 0 }, { "name": "thrU", "pagerank": 0.010389470798180462, "size": 15.034616276751176, "id": 1 }, { "name": "leuX", "pagerank": 0.008219561883974654, "size": 13.30110735388589, "id": 2 }, { "name": "glnU", "pagerank": 0.008346623167812348, "size": 13.412466666599713, "id": 3 }, { "name": "fis", "pagerank": 0.009973878955996874, "size": 14.726555106288926, "id": 4 }, { "name": "apaG", "pagerank": 0.009833503605089283, "size": 14.620272123703934, "id": 5 }, { "name": "argU", "pagerank": 0.010178173724069215, "size": 14.879190940121852, "id": 6 }, { "name": "alaX", "pagerank": 0.010109702313786295, "size": 14.82829763905088, "id": 7 }, { "name": "rrfE", "pagerank": 0.017072446967045195, "size": 19.092080332934138, "id": 8 }, { "name": "hisR", "pagerank": 0.005794555303722916, "size": 10.778108268771152, "id": 9 }, { "name": "argX", "pagerank": 0.017482365146182587, "size": 19.30354043782753, "id": 10 }, { "name": "pdxA", "pagerank": 0.010219770351963706, "size": 14.909981184158793, "id": 11 }, { "name": "metU", "pagerank": 0.010684018523665339, "size": 15.247346077337976, "id": 12 }, { "name": "leuQ", "pagerank": 0.008579265660326109, "size": 13.612628889707336, "id": 13 }, { "name": "tpr", "pagerank": 0.008206810426495442, "size": 13.289849100073056, "id": 14 }, { "name": "glnX", "pagerank": 0.010285820598740083, "size": 14.958676652334884, "id": 15 }, { "name": "rrfD", "pagerank": 0.010551725352453049, "size": 15.152352046086266, "id": 16 }, { "name": "tyrU", "pagerank": 0.008218262149548378, "size": 13.299960518119086, "id": 17 }, { "name": "serX", "pagerank": 0.008545148425897715, "size": 13.583566985420706, "id": 18 }, { "name": "gyrB", "pagerank": 0.030822534176077967, "size": 25.0, "id": 19 }, { "name": "alaV", "pagerank": 0.010737922876855325, "size": 15.285800912573384, "id": 20 }, { "name": "valX", "pagerank": 0.008068597853407945, "size": 13.16682559405072, "id": 21 }, { "name": "queA", "pagerank": 0.012646259110011935, "size": 16.565089120315125, "id": 22 }, { "name": "leuP", "pagerank": 0.007881178970106689, "size": 12.99698076125658, "id": 23 }, { "name": "glnV", "pagerank": 0.009848259682501933, "size": 14.63149961825399, "id": 24 }, { "name": "topA", "pagerank": 0.007804345307925558, "size": 12.92629993550234, "id": 25 }, { "name": "trmA", "pagerank": 0.012501732797280266, "size": 16.47319676325541, "id": 26 }, { "name": "aldB", "pagerank": 0.018090388027770472, "size": 19.61155968471118, "id": 27 }, { "name": "pheU", "pagerank": 0.017256460161113034, "size": 19.187395112130922, "id": 28 }, { "name": "leuW", "pagerank": 0.00835949362334546, "size": 13.423664506386862, "id": 29 }, { "name": "glnW", "pagerank": 0.008530311987501451, "size": 13.570898196312228, "id": 30 }, { "name": "apaH", "pagerank": 0.008396986701511337, "size": 13.456200551282604, "id": 31 }, { "name": "rrsE", "pagerank": 0.015141102428863264, "size": 18.04975529168131, "id": 32 }, { "name": "thrW", "pagerank": 0.005595030269346987, "size": 10.5194078958677, "id": 33 }, { "name": "proL", "pagerank": 0.013903967231554031, "size": 17.335897914458123, "id": 34 }, { "name": "flxA", "pagerank": 0.005722949829582605, "size": 10.686620067671964, "id": 35 }, { "name": "ilvH", "pagerank": 0.015314990195668126, "size": 18.146986209902586, "id": 36 }, { "name": "valY", "pagerank": 0.0060148636351118195, "size": 11.05092088525233, "id": 37 }, { "name": "glyT", "pagerank": 0.006069810033519178, "size": 11.117066811261521, "id": 38 }, { "name": "pyrD", "pagerank": 0.008312543701910808, "size": 13.38274385013009, "id": 39 }, { "name": "trg", "pagerank": 0.00594611195878847, "size": 10.96712317891607, "id": 40 }, { "name": "ksgA", "pagerank": 0.007985365048157325, "size": 13.091837497095446, "id": 41 }, { "name": "rrsB", "pagerank": 0.01519686040280696, "size": 18.081011584078432, "id": 42 }, { "name": "tyrT", "pagerank": 0.009687921696315374, "size": 14.50879229017634, "id": 43 }, { "name": "proK", "pagerank": 0.010017514622110943, "size": 14.759357345761758, "id": 44 }, { "name": "gltX", "pagerank": 0.01934168218080176, "size": 20.225860063519715, "id": 45 }, { "name": "hns", "pagerank": 0.011967125091479123, "size": 16.126690107523938, "id": 46 }, { "name": "metT", "pagerank": 0.003669620013623429, "size": 6.503387779011353, "id": 47 }, { "name": "thrT", "pagerank": 0.0035550544995713966, "size": 5.762890913893635, "id": 48 }, { "name": "alaT", "pagerank": 0.012906666559106439, "size": 16.72884361082998, "id": 49 }, { "name": "proP", "pagerank": 0.007961896904071744, "size": 13.07056809033766, "id": 50 }, { "name": "gltW", "pagerank": 0.005767849367790557, "size": 10.744157269992208, "id": 51 }, { "name": "rrlB", "pagerank": 0.005775741961775668, "size": 10.754211901200737, "id": 52 }, { "name": "msrA", "pagerank": 0.018535148767478093, "size": 19.832821587537772, "id": 53 }, { "name": "valU", "pagerank": 0.0036463349494215685, "size": 6.385312894673897, "id": 54 }, { "name": "aspV", "pagerank": 0.030301142018135482, "size": 24.80814408374615, "id": 55 }, { "name": "rrfA", "pagerank": 0.012161316950574591, "size": 16.253789729173896, "id": 56 }, { "name": "tufB", "pagerank": 0.0036463349494215685, "size": 6.385312894673897, "id": 57 }, { "name": "ileV", "pagerank": 0.008440196475548358, "size": 13.49354288864139, "id": 58 }, { "name": "lysT", "pagerank": 0.005840472416674523, "size": 10.836020535985188, "id": 59 }, { "name": "tyrV", "pagerank": 0.008187736217055621, "size": 13.272979893326868, "id": 60 }, { "name": "leuV", "pagerank": 0.00982068662548268, "size": 14.610509391168225, "id": 61 }, { "name": "argW", "pagerank": 0.006025484232896605, "size": 11.063762496705628, "id": 62 }, { "name": "lysW", "pagerank": 0.014391052153939703, "size": 17.62177752738412, "id": 63 }, { "name": "lrp", "pagerank": 0.009867596872176742, "size": 14.646192972133909, "id": 64 }, { "name": "rrsG", "pagerank": 0.005588242450433451, "size": 10.51039332216377, "id": 65 }, { "name": "rrfF", "pagerank": 0.007958919223400954, "size": 13.067865380780576, "id": 66 }, { "name": "rrfC", "pagerank": 0.012584528186100378, "size": 16.525929152710205, "id": 67 }, { "name": "lysV", "pagerank": 0.010544640460836628, "size": 15.147239602355416, "id": 68 }, { "name": "proM", "pagerank": 0.008329766859491015, "size": 13.397778382843308, "id": 69 }, { "name": "rrlG", "pagerank": 0.007942376642637774, "size": 13.052833891238215, "id": 70 }, { "name": "rrlA", "pagerank": 0.007990657472138868, "size": 13.096626351360696, "id": 71 }, { "name": "ilvI", "pagerank": 0.016878339994369836, "size": 18.990833464053345, "id": 72 }, { "name": "cspI", "pagerank": 0.007985788406611695, "size": 13.092220677629083, "id": 73 }, { "name": "glyU", "pagerank": 0.01073180272629578, "size": 15.281442095346861, "id": 74 }, { "name": "rrsC", "pagerank": 0.010521996899098746, "size": 15.130882753779233, "id": 75 }, { "name": "pheV", "pagerank": 0.006296115178718461, "size": 11.382276785435716, "id": 76 }, { "name": "ogt", "pagerank": 0.01183817824025872, "size": 16.04148543305811, "id": 77 }, { "name": "alaW", "pagerank": 0.005933181924227723, "size": 10.951231638124007, "id": 78 }, { "name": "rrlD", "pagerank": 0.007940978494928164, "size": 13.051562171990161, "id": 79 }, { "name": "thrV", "pagerank": 0.014680597511211032, "size": 17.78868915654325, "id": 80 }, { "name": "valT", "pagerank": 0.003515322332494345, "size": 5.0, "id": 81 }, { "name": "serT", "pagerank": 0.009586892217980428, "size": 14.430654079369345, "id": 82 }, { "name": "mazG", "pagerank": 0.012090030572364754, "size": 16.207299855912765, "id": 83 }, { "name": "ileT", "pagerank": 0.014852164102670222, "size": 17.886570632256706, "id": 84 }, { "name": "rrlH", "pagerank": 0.008401047091601272, "size": 13.459716599656858, "id": 85 }, { "name": "rrlE", "pagerank": 0.012343131399158554, "size": 16.37150067860574, "id": 86 }, { "name": "katE", "pagerank": 0.007536266647455107, "size": 12.674592859828019, "id": 87 }, { "name": "rrfG", "pagerank": 0.010120410871323756, "size": 14.836274446448702, "id": 88 }, { "name": "alaU", "pagerank": 0.004015609778843402, "size": 7.707080176295183, "id": 89 }, { "name": "rrfB", "pagerank": 0.005865509412729086, "size": 10.867357262538913, "id": 90 }, { "name": "rrsH", "pagerank": 0.013467818583971268, "size": 17.074171139366584, "id": 91 }, { "name": "gltV", "pagerank": 0.008317958964269982, "size": 13.387473875095866, "id": 92 }, { "name": "rrlC", "pagerank": 0.008398920454398403, "size": 13.45787524478182, "id": 93 }, { "name": "rrsD", "pagerank": 0.008238361719897622, "size": 13.317677922608995, "id": 94 }, { "name": "rrsA", "pagerank": 0.003789529608361911, "size": 7.004152676498159, "id": 95 }, { "name": "gltT", "pagerank": 0.012651649922563873, "size": 16.568502572287834, "id": 96 }, { "name": "ileU", "pagerank": 0.008009672861393296, "size": 13.113809121093023, "id": 97 }, { "name": "rrfH", "pagerank": 0.010669080946924966, "size": 15.236664194841172, "id": 98 }, { "name": "gltU", "pagerank": 0.005629263823069513, "size": 10.564649277490576, "id": 99 } ], "links": [ { "id": "e0", "source": "n0", "target": "n1" }, { "id": "e1", "source": "n0", "target": "n2" }, { "id": "e2", "source": "n0", "target": "n3" }, { "id": "e3", "source": "n1", "target": "n56" }, { "id": "e4", "source": "n1", "target": "n8" }, { "id": "e74", "source": "n1", "target": "n29" }, { "id": "e5", "source": "n2", "target": "n49" }, { "id": "e6", "source": "n2", "target": "n32" }, { "id": "e112", "source": "n3", "target": "n55" }, { "id": "e121", "source": "n3", "target": "n60" }, { "id": "e7", "source": "n4", "target": "n5" }, { "id": "e8", "source": "n4", "target": "n6" }, { "id": "e9", "source": "n4", "target": "n7" }, { "id": "e10", "source": "n4", "target": "n8" }, { "id": "e11", "source": "n5", "target": "n61" }, { "id": "e12", "source": "n5", "target": "n46" }, { "id": "e56", "source": "n5", "target": "n24" }, { "id": "e13", "source": "n6", "target": "n55" }, { "id": "e50", "source": "n6", "target": "n22" }, { "id": "e88", "source": "n6", "target": "n41" }, { "id": "e14", "source": "n7", "target": "n74" }, { "id": "e20", "source": "n7", "target": "n10" }, { "id": "e124", "source": "n7", "target": "n61" }, { "id": "e15", "source": "n8", "target": "n80" }, { "id": "e16", "source": "n8", "target": "n91" }, { "id": "e64", "source": "n8", "target": "n27" }, { "id": "e84", "source": "n8", "target": "n35" }, { "id": "e159", "source": "n8", "target": "n78" }, { "id": "e17", "source": "n9", "target": "n10" }, { "id": "e18", "source": "n9", "target": "n11" }, { "id": "e19", "source": "n10", "target": "n19" }, { "id": "e21", "source": "n10", "target": "n49" }, { "id": "e22", "source": "n10", "target": "n50" }, { "id": "e23", "source": "n10", "target": "n51" }, { "id": "e24", "source": "n10", "target": "n52" }, { "id": "e41", "source": "n11", "target": "n19" }, { "id": "e72", "source": "n11", "target": "n28" }, { "id": "e113", "source": "n11", "target": "n55" }, { "id": "e25", "source": "n12", "target": "n13" }, { "id": "e26", "source": "n12", "target": "n14" }, { "id": "e27", "source": "n12", "target": "n15" }, { "id": "e28", "source": "n12", "target": "n16" }, { "id": "e29", "source": "n13", "target": "n40" }, { "id": "e30", "source": "n13", "target": "n20" }, { "id": "e37", "source": "n14", "target": "n18" }, { "id": "e40", "source": "n14", "target": "n19" }, { "id": "e31", "source": "n15", "target": "n84" }, { "id": "e49", "source": "n15", "target": "n21" }, { "id": "e61", "source": "n15", "target": "n26" }, { "id": "e32", "source": "n16", "target": "n75" }, { "id": "e33", "source": "n16", "target": "n94" }, { "id": "e60", "source": "n16", "target": "n25" }, { "id": "e34", "source": "n17", "target": "n18" }, { "id": "e35", "source": "n17", "target": "n19" }, { "id": "e36", "source": "n17", "target": "n20" }, { "id": "e38", "source": "n18", "target": "n58" }, { "id": "e39", "source": "n19", "target": "n81" }, { "id": "e42", "source": "n19", "target": "n82" }, { "id": "e43", "source": "n19", "target": "n40" }, { "id": "e44", "source": "n19", "target": "n39" }, { "id": "e45", "source": "n19", "target": "n27" }, { "id": "e46", "source": "n19", "target": "n36" }, { "id": "e53", "source": "n19", "target": "n23" }, { "id": "e99", "source": "n19", "target": "n45" }, { "id": "e123", "source": "n19", "target": "n61" }, { "id": "e170", "source": "n20", "target": "n85" }, { "id": "e172", "source": "n20", "target": "n86" }, { "id": "e47", "source": "n21", "target": "n22" }, { "id": "e48", "source": "n21", "target": "n23" }, { "id": "e51", "source": "n22", "target": "n35" }, { "id": "e52", "source": "n22", "target": "n36" }, { "id": "e67", "source": "n22", "target": "n28" }, { "id": "e54", "source": "n23", "target": "n80" }, { "id": "e55", "source": "n24", "target": "n25" }, { "id": "e57", "source": "n24", "target": "n26" }, { "id": "e58", "source": "n24", "target": "n27" }, { "id": "e59", "source": "n25", "target": "n53" }, { "id": "e62", "source": "n26", "target": "n79" }, { "id": "e71", "source": "n26", "target": "n28" }, { "id": "e79", "source": "n26", "target": "n33" }, { "id": "e63", "source": "n27", "target": "n86" }, { "id": "e65", "source": "n27", "target": "n87" }, { "id": "e66", "source": "n27", "target": "n88" }, { "id": "e83", "source": "n27", "target": "n34" }, { "id": "e164", "source": "n27", "target": "n83" }, { "id": "e68", "source": "n28", "target": "n29" }, { "id": "e69", "source": "n28", "target": "n30" }, { "id": "e70", "source": "n28", "target": "n31" }, { "id": "e73", "source": "n28", "target": "n32" }, { "id": "e75", "source": "n29", "target": "n37" }, { "id": "e76", "source": "n30", "target": "n38" }, { "id": "e77", "source": "n30", "target": "n39" }, { "id": "e126", "source": "n31", "target": "n62" }, { "id": "e143", "source": "n31", "target": "n68" }, { "id": "e78", "source": "n32", "target": "n51" }, { "id": "e110", "source": "n32", "target": "n53" }, { "id": "e151", "source": "n32", "target": "n74" }, { "id": "e156", "source": "n32", "target": "n77" }, { "id": "e80", "source": "n33", "target": "n34" }, { "id": "e81", "source": "n34", "target": "n82" }, { "id": "e82", "source": "n34", "target": "n53" }, { "id": "e94", "source": "n34", "target": "n43" }, { "id": "e129", "source": "n34", "target": "n63" }, { "id": "e90", "source": "n36", "target": "n41" }, { "id": "e98", "source": "n36", "target": "n44" }, { "id": "e103", "source": "n36", "target": "n47" }, { "id": "e141", "source": "n36", "target": "n67" }, { "id": "e85", "source": "n37", "target": "n55" }, { "id": "e86", "source": "n38", "target": "n42" }, { "id": "e87", "source": "n39", "target": "n85" }, { "id": "e89", "source": "n41", "target": "n42" }, { "id": "e91", "source": "n42", "target": "n52" }, { "id": "e101", "source": "n42", "target": "n45" }, { "id": "e105", "source": "n42", "target": "n49" }, { "id": "e188", "source": "n42", "target": "n96" }, { "id": "e92", "source": "n43", "target": "n44" }, { "id": "e93", "source": "n43", "target": "n45" }, { "id": "e95", "source": "n43", "target": "n46" }, { "id": "e96", "source": "n44", "target": "n60" }, { "id": "e97", "source": "n44", "target": "n53" }, { "id": "e100", "source": "n45", "target": "n71" }, { "id": "e102", "source": "n45", "target": "n72" }, { "id": "e104", "source": "n45", "target": "n48" }, { "id": "e128", "source": "n45", "target": "n63" }, { "id": "e142", "source": "n45", "target": "n68" }, { "id": "e116", "source": "n46", "target": "n55" }, { "id": "e163", "source": "n46", "target": "n82" }, { "id": "e176", "source": "n46", "target": "n87" }, { "id": "e120", "source": "n49", "target": "n59" }, { "id": "e122", "source": "n49", "target": "n60" }, { "id": "e106", "source": "n50", "target": "n91" }, { "id": "e107", "source": "n50", "target": "n72" }, { "id": "e108", "source": "n53", "target": "n56" }, { "id": "e109", "source": "n53", "target": "n84" }, { "id": "e114", "source": "n53", "target": "n55" }, { "id": "e148", "source": "n53", "target": "n73" }, { "id": "e111", "source": "n54", "target": "n55" }, { "id": "e115", "source": "n55", "target": "n70" }, { "id": "e117", "source": "n55", "target": "n72" }, { "id": "e118", "source": "n55", "target": "n57" }, { "id": "e119", "source": "n55", "target": "n59" }, { "id": "e127", "source": "n55", "target": "n62" }, { "id": "e125", "source": "n56", "target": "n61" }, { "id": "e146", "source": "n56", "target": "n69" }, { "id": "e162", "source": "n56", "target": "n82" }, { "id": "e139", "source": "n58", "target": "n67" }, { "id": "e184", "source": "n58", "target": "n93" }, { "id": "e130", "source": "n63", "target": "n64" }, { "id": "e131", "source": "n63", "target": "n65" }, { "id": "e132", "source": "n63", "target": "n66" }, { "id": "e133", "source": "n63", "target": "n67" }, { "id": "e134", "source": "n64", "target": "n96" }, { "id": "e135", "source": "n64", "target": "n80" }, { "id": "e171", "source": "n64", "target": "n86" }, { "id": "e136", "source": "n65", "target": "n72" }, { "id": "e137", "source": "n66", "target": "n96" }, { "id": "e138", "source": "n66", "target": "n97" }, { "id": "e140", "source": "n67", "target": "n94" }, { "id": "e178", "source": "n67", "target": "n88" }, { "id": "e144", "source": "n68", "target": "n69" }, { "id": "e145", "source": "n68", "target": "n70" }, { "id": "e158", "source": "n69", "target": "n78" }, { "id": "e167", "source": "n70", "target": "n83" }, { "id": "e147", "source": "n71", "target": "n85" }, { "id": "e165", "source": "n71", "target": "n83" }, { "id": "e168", "source": "n72", "target": "n83" }, { "id": "e174", "source": "n72", "target": "n86" }, { "id": "e191", "source": "n72", "target": "n99" }, { "id": "e149", "source": "n73", "target": "n74" }, { "id": "e150", "source": "n73", "target": "n75" }, { "id": "e153", "source": "n74", "target": "n76" }, { "id": "e152", "source": "n75", "target": "n79" }, { "id": "e189", "source": "n75", "target": "n98" }, { "id": "e154", "source": "n76", "target": "n77" }, { "id": "e155", "source": "n77", "target": "n84" }, { "id": "e157", "source": "n77", "target": "n89" }, { "id": "e161", "source": "n79", "target": "n80" }, { "id": "e160", "source": "n80", "target": "n99" }, { "id": "e175", "source": "n80", "target": "n87" }, { "id": "e166", "source": "n83", "target": "n84" }, { "id": "e169", "source": "n84", "target": "n97" }, { "id": "e181", "source": "n84", "target": "n92" }, { "id": "e173", "source": "n86", "target": "n90" }, { "id": "e177", "source": "n88", "target": "n91" }, { "id": "e179", "source": "n88", "target": "n97" }, { "id": "e190", "source": "n90", "target": "n98" }, { "id": "e180", "source": "n91", "target": "n98" }, { "id": "e185", "source": "n91", "target": "n95" }, { "id": "e182", "source": "n92", "target": "n93" }, { "id": "e183", "source": "n92", "target": "n94" }, { "id": "e186", "source": "n93", "target": "n96" }, { "id": "e187", "source": "n96", "target": "n98" } ] }
To selfhost it one could
git clone https://github.com/holtzy/D3-graph-gallery.git
cd D3-graph-gallery
grep -rni d3-graph-gallery | cut -d: -f1 | xargs -I% sed -i "s,https://www.d3-graph-gallery.com,<your selfhost url>,g" %
In the code section in page https://www.d3-graph-gallery.com/graph/arc_highlight.html, I think there is a typo:
// Add the highlighting functionality nodes .on('mouseover', function (d) { // Highlight the nodes: every node is green except of him nodes.style('fill', "#B8B8B8") d3.select(this).style('fill', '#69b3b2')
It should be every node is grey except of him
since the highlighted node is in green while the other nodes are in grey.
hello, Please, why didn't you use people's names? Where do these numbers come from? var mygroup = [1,2,3]
How can I use the names instead of numbers? Thank you
https://www.d3-graph-gallery.com/graph/stackedarea_basic.html
// Stack the data: each group will be represented on top of each other var mygroups = ["Helen", "Amanda", "Ashley"] // list of group names var mygroup = [1,2,3] // list of group names var stackedData = d3.stack() .keys(mygroup) .value(function(d, key){ return d.values[key].n }) (sumstat)
Dear Yan,
I'm a novice at dataviz. I'm struggling on visualizing my data using ggraph
with multiple hierarchical levels. I got some thing wrong.
when I plot under default mode ggraph()
, it works well. But it resulted in overlapped layout when I want to set the node size based on variable mean
under weight mode ggraph(weight=mean)
.
I have been struggling for several days, and don't know where to improve it.
Any suggestions would be appreciated.
please find my data in the attachment.
please pay attention to line 22-37 in my R script, which denote two subsets of my data, both work well under default mode, but one works under weight mode and the other fails.
I tried to use the d3.js scatterplot example(s) (both v4 and v6).
The tooltip was under the plot in a fixed place.
Then I put style: position: absolute to tooltip div and it worked.
I am getting a 404 when I am trying to access https://www.d3-graph-gallery.com/sunburst.html I also cannot find it - is it not created yet?
Ah and btw - great content thank you so much for this website - you helped me a lot to get started. :D
The calculations below from https://www.d3-graph-gallery.com/graph/boxplot_basic.html are not correct.
var min = q1 - 1.5 * interQuantileRange
var max = q1 + 1.5 * interQuantileRange
Outliers are more than 1.5 * IQR above Q3 and below Q1. Those cutoffs are called fences. The whiskers are not fences: they indicate the highest and lowest nonoutlier data values.
See: https://ggplot2.tidyverse.org/reference/geom_boxplot.html
If you don't want to indicate outliers than just set min and max to the min and max values of the dataset.
Hey first i want to thank you for u'r cool explanations.
I found a small improvement at this side.
You’re describing 3 ways how to get the mouse position. The first way is not a good solution because it does not work in every browser. Instead of event.pageX()
you should use d3.event.pageX
. It works really good for me. Especially when u zoom in and out it’s the only solution that really works.
Hi @holtzy !
I'm trying to make a radarchart in R.
It's about a frog's daily vocal activity. But I'm having some trouble (like always in R) with the script.
my radarchart sequence must be between (0 ,2) and by 0.2.
But when I try it the graph it is out of bounds.
Could you please give me a hand here?
I've attached my data.frame and r script.
cheers,
Martín.
Script
read.csv("D:/Tesis/Gastros/grafico_circular.csv", header = T, sep = ";", dec = ".")-> G.chrys
library("fmsb")
colnames(G.chrys) <- c(24:1)
View(G.chrys)
#plot circular
windows()
radarchart(G.chrys, axistype = 1, caxislabels = seq(0,2,0.2), cglcol = "grey",vlcex = 0.8, cglty = 1, cglwd = 0.5,axislabcol = "grey", pcol = "black",plwd = 1.8, plty = 1)
https://www.d3-graph-gallery.com/graph/connectedscatter_tooltip.html
in the d3.v6 example.
const mousemove = function(event,d) {
Tooltip
.html("Exact value: " + d.value)
.style("left", (event.x)/2 + "px")
.style("top", (event.y)/2 + "px")
}
(event.x)/2 and (event.y)/2 is not mouse mouse position.
x position is d3.pointer(event)[0] + 70
y position is d3.pointer(event)[1]
Hi, I was just looking at the code example for basic boxplot as provided in D3 graph gallery.
I noticed that "max" value for the boxplot is incorrect.
As far as I know, max('upper fence') is upper quartile + 1.5 * IQR.
However, the code in the example is var max = q1 + 1.5 * interQuantileRange
.
Perhaps it should be q3 + 1.5 * interQuantileRange
instead?
No issue, but just a thank you for the work and time you've spent on www.d3-graph-gallery.com. So much more readable (and copy-able) then https://observablehq.com
Hello is there an interactive gist to this Hierarchical Edge Bundling in a matrix/ tree layout , the link for Dan's interactive sample/code is broken
Hi! Nice set of sample charts, I especially appreciated the stacked area example. I was hoping to make a simple adaptation and re-publish some of the code for the stacked area example in a github template repo that I expect may be forked a lot. But seeing as this code does not have any published license, this may be a bad idea.
Do you intend to apply a general open-source license to this repo and the example code in particular? (If you do and are unsure what license is appropriate, perhaps https://choosealicense.com can help. If not that's fine too.)
#30 is related but the author closed it before any discussion occurred.
Hi Yan,
Any chance why the radio button change does not work on your homepage?
the color does not change of the circles.
And the code does not work either when I try to implement it. Always throws an error because of the $
-sign.
I'm trying to implement a listener to a radio button using D3 and js, until now it does not work yet however :').
tried getting inspired by the amazing website you did (really cool)! the radio button example does not work however on my end.
thanks in advance for any help you can provide!!
best,
jas zoe
I have read this great article and Im trying to do my own circular stacked barplot.
I have one problem. I dont know how to add the labels inside the stacked bars in order to create the polar coord afterwards.
I paste the code I took from your article:
p <- ggplot(data) +
geom_bar(aes(x=as.factor(id), y=value, fill=observation), stat="identity", alpha=0.5) +
scale_fill_manual(values=c("#1E8E6B", "#6FBC84", "#FEEF51", "#EF6541", "#E81329")) +
geom_segment(data=grid_data, aes(x = end, y = 0, xend = start, yend = 0), colour = "grey", alpha=0, size=0 , inherit.aes = FALSE ) +
geom_segment(data=grid_data, aes(x = end, y = 25, xend = start, yend = 25), colour = "grey", alpha=0, size=0 , inherit.aes = FALSE ) +
geom_segment(data=grid_data, aes(x = end, y = 50, xend = start, yend = 50), colour = "grey", alpha=0, size=0 , inherit.aes = FALSE ) +
geom_segment(data=grid_data, aes(x = end, y = 75, xend = start, yend = 75), colour = "grey", alpha=0, size=0 , inherit.aes = FALSE ) +
geom_segment(data=grid_data, aes(x = end, y = 100, xend = start, yend = 100), colour = "grey", alpha=0, size=0 , inherit.aes = FALSE ) +
ggplot2::annotate("text", x = rep(max(data$id),5), y = c(0, 25, 50, 75, 100), label = c("0", "25", "50", "75", "100") , color="grey", size=5 , angle=0, fontface="bold", hjust=0) +
ylim(0,max(label_data$tot, na.rm=T)) +
theme_minimal() +
theme(
legend.position = "none",
axis.text = element_blank(),
axis.title = element_blank(),
panel.grid = element_blank(),
plot.margin = unit(rep(-1,4), "cm")
) +
coord_polar() +
geom_text(data=label_data, aes(x=id, y=tot+10, label=Area, hjust=hjust), color="black", fontface="bold",alpha=0.6, size=2.5, angle= label_data$angle, inherit.aes = FALSE ) +
geom_segment(data=base_data, aes(x = start, y = -5, xend = end, yend = -5), colour = "black", alpha=0.8, size=0.6, inherit.aes = FALSE ) +
geom_text(data=base_data, aes(x = title, y = -18, label=group), hjust=c(1,1,0,0), colour = "black", alpha=0.8, size=4, fontface="bold", inherit.aes = FALSE)
Best,
Juan
The link to Data Art
links to https://www.r-graph-gallery.com/portfolio/data-art/, which results in a 404 - Not found.
Inspired by here
The d3 link is broken, because href is emtpy in the anchor tag.
The online course link presents the user with the following statement: "Invalid Publisher Code, Offer, or Publisher - Advertiser Partnership Status".
For some reason, some examples don't work as expected on Firefox. Like,
A declarative, efficient, and flexible JavaScript library for building user interfaces.
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google ❤️ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.