rich-iannone / DiagrammeR

Graph and network visualization using tabular data in R
https://rich-iannone.github.io/DiagrammeR/
Other
1.69k stars 248 forks source link

subgraph #260

Open ghost opened 6 years ago

ghost commented 6 years ago

I'm trying to join nodes to a cluster subgraph of nodes with lhead but it does not work. Here is the code I'm producing:

grViz(" digraph G {

  graph [compund = true]

  edge [color = grey,
  arrowhead = vee]

  node [shape = oval,
  label = 'Esthwaite Water',
  style = filled,
  color = aliceblue]  
  a

  node [shape = oval,
  label = 'Western Shore',
  style = filled,
  color = aliceblue]
  b
  a->b

  node [shape = oval,
  label = 'Lake',
  style = filled,
  color = aliceblue]
  c
  a->c

  subgraph cluster0 {
  node [shape = egg,
  label = '3'
  style = filled,
  color = lemonchiffon]
  d
  node [shape = egg,
  label = '2'
  style = filled,
  color = lemonchiffon]
  e
  node [shape = egg,
  label = '1'
  style = filled,
  color = lemonchiffon]
  f
  label = 'Kick Samples'
  labelloc = 'b'
  color = grey
  fontsize = 15
  fontcolor = grey
  }

  subgraph cluster1 {
  node [shape = egg,
  label = '7'
  style = filled,
  color = lemonchiffon]
  g
  node [shape = egg,
  label = '6'
  style = filled,
  color = lemonchiffon]
  h
  node [shape = egg,
  label = '5'
  style = filled,
  color = lemonchiffon]
  i
  node [shape = egg,
  label = '4'
  style = filled,
  color = lemonchiffon]
  j
  label = 'Ekman Grab Samples'
  labelloc = 'b'
  color = grey
  fontsize = 15
  fontcolor = grey
  }
  b->e[ltail=b lhead=cluster0]
  c->h[ltail=c lhead=cluster1]
  }
  ")
ghost commented 6 years ago

I've just managed to solve it, by introducing graph[compound=true] inside the subgraph {} also the main graph[] command is wrong as is not compund but compound.

komalsrathi commented 6 years ago

Hi @TomONeillQMUL I have a similar question and hopefully you will be able to help me here:

I have created this graph and I am clustering the top half and the bottom half. Here is my code:

digraph datatracker {

    graph [compound = true]

    edge [color = grey,
          arrowhead = vee]

    # top node statements
    subgraph cluster1 {
        node [shape = box,
        fontname = Helvetica,
        width = 2, 
        penwidth = 2,
        style = filled,
        fillcolor = lightblue,
        label = A1,
        tooltip = 'A1',
        color = lightblue]
        A1

        node [shape = box,
        fontname = Helvetica,
        width = 2, 
        penwidth = 2,
        style = filled,
        fillcolor = lightblue,
        label = P1,
        tooltip = 'P1',
        color = lightblue]
        P1

        node [shape = box,
        fontname = Helvetica,
        width = 2, 
        penwidth = 2,
        style = filled,
        fillcolor = lightblue,
        label = P2,
        tooltip = 'P2',
        color = lightblue]
        P2
        P1->P2

        rank = same; P2; A1  # rank does not seem to work
        label = 'Cluster 1'
        color = grey
        fontsize = 15
        fontcolor = grey
    }

    # bottom node statements
    subgraph cluster2 {

        node [shape = box,
        fontname = Helvetica,
        width = 2,
        penwidth = 2,
        style = filled,
        fillcolor = steelblue,
        label = A2,
        tooltip = 'A2',
        color = steelblue]
        A2
        A1->A2

        node [shape = box,
        fontname = Helvetica,
        width = 2,
        penwidth = 2,
        style = filled,
        fillcolor = steelblue,
        label = A3,
        tooltip = 'A3',
        color = steelblue]
        A3
        A2->A3

        node [shape = box,
        fontname = Helvetica,
        width = 2,
        penwidth = 2,
        style = filled,
        fillcolor = steelblue,
        label = P3,
        tooltip = 'P3',
        color = steelblue]
        P3
        P2->P3

        node [shape = box,
        fontname = Helvetica,
        width = 2,
        penwidth = 2,
        style = filled,
        fillcolor = steelblue,
        label = P4,
        tooltip = 'P4',
        color = steelblue]
        P4
        P3->P4
        A2->P4

        node [shape = box,
        fontname = Helvetica,
        width = 2,
        penwidth = 2,
        style = filled,
        fillcolor = steelblue,
        label = P5,
        tooltip = 'P5',
        color = steelblue]
        P5
        P4->P5

        node [shape = box,
        fontname = Helvetica,
        width = 2,
        penwidth = 2,
        style = filled,
        fillcolor = steelblue,
        alpha = 0.5,
        label = AP,
        tooltip = 'AP',
        color = steelblue]
        AP
        P5->AP
        A3->AP

        rank = same; P4; A2 # rank does not seem to work
        label = 'Cluster 2'
        color = red
        fontsize = 15
        fontcolor = red 
    }
}

This produces the following figure:

rplot

However, what I am trying to achieve is the rank of P4 and A2 should be same as well as A1 and P2 should be at the same rank such that the graph looks like this:

rplot 6 00 12 pm

Also not sure how to reconfigure the plot so that As are on the left and Ps are on the right. Can you help me?

trenvort commented 1 year ago

Hi @TomONeillQMUL I have a similar question and hopefully you will be able to help me here:

I have created this graph and I am clustering the top half and the bottom half. Here is my code: digraph MapaConceptual { rankdir=LR; node [shape=box, style="filled, rounded", fillcolor="#F9F9F9"];

subgraph cluster_0 {
    label="Evaluaciones en México y América Latina en 2012";
    style=filled;
    fillcolor="#D9EDF7";
    fontcolor="#154360";
    fontname="Arial";

    node [fillcolor="#2980B9", fontcolor="white"];
    PruebasDeAprendizaje [label="Pruebas de aprendizaje"];
    ExperienciaMéxico [label="Experiencia de México en pruebas estandarizadas"];

    node [fillcolor="#3498DB"];
    Normal [label="Exámenes de ingreso a normal"];
    IDANIS [label="IDANIS"];
    EstudioPrimaria [label="Estudio de Evaluación de Primaria"];

    node [fillcolor="#2980B9"];
    ANMEB [label="Acuerdo Nacional para la Modernización de la Educación Básica (ANMEB)"];
    ProgramaCarreraMagisterial [label="Programa de Carrera Magisterial"];

    node [fillcolor="#3498DB"];
    PARE [label="Programa para Abatir el Rezago Educativo (PARE)"];

    node [fillcolor="#2980B9"];
    OCDE [label="Ingreso de México a la OCDE"];
    PISA [label="Participación en el proyecto PISA"];
    TIMSS [label="Participación en el Tercer Estudio Internacional de Matemáticas y Ciencias (TIMSS)"];
    LLECE [label="Participación en el Laboratorio Latinoamericano de Evaluación de la Calidad Educativa (LLECE)"];

    node [fillcolor="#3498DB"];
    ReformaCurricular [label="Reforma curricular"];
    PruebasEstándaresNacionales [label="Pruebas de Estándares Nacionales"];

    node [fillcolor="#2980B9"];
    IDANIS [label="IDANIS"];
    OlimpiadasConocimiento [label="Olimpiadas del Conocimiento"];

    node [fillcolor="#3498DB"];
    INEE [label="Instituto Nacional para la Evaluación de la Educación (INEE)"];

    node [fillcolor="#2980B9"];
    EXCALE [label="Exámenes de la Calidad y el Logro Educativo (EXCALE)"];
    ENLACE [label="Exámenes Nacionales del Logro Educativo en Centros Escolares (ENLACE)"];
}

subgraph cluster_1 {
    label="Desarrollo de pruebas y consecuencias negativas";
    style=filled;
    fillcolor="#E8DAEF";
    fontcolor="#6C3483";
    fontname="Arial";

    node [fillcolor="#913D88", fontcolor="white"];
    DesarrolloPruebas [label="Desarrollo de nuevos instrumentos de evaluación"];
    MejoraCalidad [label="Mejora de la calidad técnica del INEE"];

    node [fillcolor="#9B59