June 20, 2014

Julia 0.3で箱ひげ図を描く

データやパッケージのロードは、「Julia 0.3でヒストグラムを描く」を参照してください。

箱ひげ図を描くには、次のようなコマンドを打つ。

julia > plot(iris[[:SepalLength, :Species]], Geom.boxplot, x="Species", y="SepalLength")

Rでは変数が一つだけでも箱ひげ図を描くことが出来るけど、JuliaのGadflyではx軸とy軸を指定する必要があるみたい。また、x軸やy軸のラベル名も指定しないと動かなかった。

現状では、Rの方が手軽に作図出来るなあって印象です。

<script charset="utf-8">

    function draw_with_data(data, parent_id) {

var g = d3.select(parent_id)

        .append("svg")

          .attr("width", "120mm")

          .attr("height", "80mm")

          .attr("viewBox", "0 0 120 80")

          .attr("stroke-width", "0.5")

          .attr("style", "stroke:black;fill:black");

g.append(“defs”);

var ctx = {

  "scale": 1.0,

  "tx": 0.0,

  "ty": 0.0

};

(function (g) {

g.attr(“stroke”, “none”)

.attr(“fill”, “#000000”)

.attr(“stroke-width”, 0.3)

.attr(“font-family”, “Helvetic,Arial,sans”)

.style(“font-size”, “3.88px”);

(function (g) {

g.attr("class", "plotroot yscalable");

(function (g) {

  g.attr("stroke", "none")

   .attr("fill", "#4C404B")

   .attr("font-family", "'PT Sans','Helvetica Neue','Helvetica',sans-serif")

   .style("font-size", "3.18px")

   .attr("class", "guide ylabels");

  (function (g) {

    g.attr("visibility", "hidden");

    g.append("svg:text")

       .attr("x", 18.94)

       .attr("y", 95.88)

       .attr("text-anchor", "end")

       .style("dominant-baseline", "central")

        .call(function(text) {

  text.text("1");

})

;

  }(g.append("g")));

  (function (g) {

    g.attr("visibility", "hidden");

    g.append("svg:text")

       .attr("x", 18.94)

       .attr("y", -44.53)

       .attr("text-anchor", "end")

       .style("dominant-baseline", "central")

        .call(function(text) {

  text.text("12");

})

;

  }(g.append("g")));

  (function (g) {

    g.attr("visibility", "hidden");

    g.append("svg:text")

       .attr("x", 18.94)

       .attr("y", -57.29)

       .attr("text-anchor", "end")

       .style("dominant-baseline", "central")

        .call(function(text) {

  text.text("13");

})

;

  }(g.append("g")));

  g.append("svg:text")

     .attr("x", 18.94)

     .attr("y", 44.83)

     .attr("text-anchor", "end")

     .style("dominant-baseline", "central")

     .call(function(text) {

 text.text("5");

})

;

  (function (g) {

    g.attr("visibility", "hidden");

    g.append("svg:text")

       .attr("x", 18.94)

       .attr("y", 70.36)

       .attr("text-anchor", "end")

       .style("dominant-baseline", "central")

        .call(function(text) {

  text.text("3");

})

;

  }(g.append("g")));

  (function (g) {

    g.attr("visibility", "hidden");

    g.append("svg:text")

       .attr("x", 18.94)

       .attr("y", 121.41)

       .attr("text-anchor", "end")

       .style("dominant-baseline", "central")

        .call(function(text) {

  text.text("-1");

})

;

  }(g.append("g")));

  g.append("svg:text")

     .attr("x", 18.94)

     .attr("y", 57.59)

     .attr("text-anchor", "end")

     .style("dominant-baseline", "central")

     .call(function(text) {

 text.text("4");

})

;

  g.append("svg:text")

     .attr("x", 18.94)

     .attr("y", 32.06)

     .attr("text-anchor", "end")

     .style("dominant-baseline", "central")

     .call(function(text) {

 text.text("6");

})

;

  g.append("svg:text")

     .attr("x", 18.94)

     .attr("y", 6.53)

     .attr("text-anchor", "end")

     .style("dominant-baseline", "central")

     .call(function(text) {

 text.text("8");

})

;

  (function (g) {

    g.attr("visibility", "hidden");

    g.append("svg:text")

       .attr("x", 18.94)

       .attr("y", -19)

       .attr("text-anchor", "end")

       .style("dominant-baseline", "central")

        .call(function(text) {

  text.text("10");

})

;

  }(g.append("g")));

  (function (g) {

    g.attr("visibility", "hidden");

    g.append("svg:text")

       .attr("x", 18.94)

       .attr("y", -6.23)

       .attr("text-anchor", "end")

       .style("dominant-baseline", "central")

        .call(function(text) {

  text.text("9");

})

;

  }(g.append("g")));

  g.append("svg:text")

     .attr("x", 18.94)

     .attr("y", 19.3)

     .attr("text-anchor", "end")

     .style("dominant-baseline", "central")

     .call(function(text) {

 text.text("7");

})

;

  (function (g) {

    g.attr("visibility", "hidden");

    g.append("svg:text")

       .attr("x", 18.94)

       .attr("y", 108.65)

       .attr("text-anchor", "end")

       .style("dominant-baseline", "central")

        .call(function(text) {

  text.text("0");

})

;

  }(g.append("g")));

  (function (g) {

    g.attr("visibility", "hidden");

    g.append("svg:text")

       .attr("x", 18.94)

       .attr("y", -31.76)

       .attr("text-anchor", "end")

       .style("dominant-baseline", "central")

        .call(function(text) {

  text.text("11");

})

;

  }(g.append("g")));

  (function (g) {

    g.attr("visibility", "hidden");

    g.append("svg:text")

       .attr("x", 18.94)

       .attr("y", 83.12)

       .attr("text-anchor", "end")

       .style("dominant-baseline", "central")

        .call(function(text) {

  text.text("2");

})

;

  }(g.append("g")));

}(g.append("g")));

(function (g) {

  g.attr("stroke", "none")

   .attr("fill", "#362A35")

   .attr("font-family", "'PT Sans','Helvetica Neue','Helvetica',sans-serif")

   .style("font-size", "3.88px");

  g.append("svg:text")

     .attr("x", 8.65)

     .attr("y", 32.06)

     .attr("text-anchor", "middle")

     .style("dominant-baseline", "central")

     .attr("transform", "rotate(-90, 8.65, 32.06)")

     .call(function(text) {

 text.text("SepalLength");

})

;

}(g.append("g")));

(function (g) {

  g.attr("stroke", "none")

   .attr("fill", "#4C404B")

   .attr("font-family", "'PT Sans','Helvetica Neue','Helvetica',sans-serif")

   .style("font-size", "3.18px")

   .attr("class", "guide xlabels");

  g.append("svg:text")

     .attr("x", 35.78)

     .attr("y", 64.71)

     .attr("text-anchor", "middle")

     .call(function(text) {

 text.text("setosa");

})

;

  g.append("svg:text")

     .attr("x", 99.16)

     .attr("y", 64.71)

     .attr("text-anchor", "middle")

     .call(function(text) {

 text.text("virginica");

})

;

  g.append("svg:text")

     .attr("x", 67.47)

     .attr("y", 64.71)

     .attr("text-anchor", "middle")

     .call(function(text) {

 text.text("versicolor");

})

;

}(g.append("g")));

(function (g) {

  g.attr("stroke", "none")

   .attr("fill", "#362A35")

   .attr("font-family", "'PT Sans','Helvetica Neue','Helvetica',sans-serif")

   .style("font-size", "3.88px");

  g.append("svg:text")

     .attr("x", 67.47)

     .attr("y", 73)

     .attr("text-anchor", "middle")

     .call(function(text) {

 text.text("Species");

})

;

}(g.append("g")));

(function (g) {

  g.on("mouseover", guide_background_mouseover("#C6C6C9"))

   .on("mouseout", guide_background_mouseout("#F0F0F3"))

   .call(zoom_behavior(ctx))

;

  (function (g) {

    d3.select("defs")

.append(“svg:clipPath”)

.attr("id", parent_id + "_clippath0")

.append("svg:path")

  .attr("d", " M19.94,5 L 115 5 115 59.12 19.94 59.12 z");g.attr("clip-path", "url(#" + parent_id + "_clippath0)");

    (function (g) {

      g.attr("class", "guide background")

       .attr("stroke", "#F1F1F5")

       .attr("fill", "#FAFAFA")

       .attr("opacity", 1.00);

      g.append("svg:path")

         .attr("d", "M19.94,5 L 115 5 115 59.12 19.94 59.12 z");

    }(g.append("g")));

    (function (g) {

      g.attr("stroke", "#F0F0F3")

       .attr("stroke-width", 0.2)

       .attr("class", "guide ygridlines xfixed");

      g.append("svg:path")

         .attr("d", "M19.94,-44.53 L 115 -44.53");

      g.append("svg:path")

         .attr("d", "M19.94,44.83 L 115 44.83");

      g.append("svg:path")

         .attr("d", "M19.94,121.41 L 115 121.41");

      g.append("svg:path")

         .attr("d", "M19.94,32.06 L 115 32.06");

      g.append("svg:path")

         .attr("d", "M19.94,-19 L 115 -19");

      g.append("svg:path")

         .attr("d", "M19.94,19.3 L 115 19.3");

      g.append("svg:path")

         .attr("d", "M19.94,-31.76 L 115 -31.76");

      g.append("svg:path")

         .attr("d", "M19.94,83.12 L 115 83.12");

      g.append("svg:path")

         .attr("d", "M19.94,108.65 L 115 108.65");

      g.append("svg:path")

         .attr("d", "M19.94,-6.23 L 115 -6.23");

      g.append("svg:path")

         .attr("d", "M19.94,6.53 L 115 6.53");

      g.append("svg:path")

         .attr("d", "M19.94,57.59 L 115 57.59");

      g.append("svg:path")

         .attr("d", "M19.94,70.36 L 115 70.36");

      g.append("svg:path")

         .attr("d", "M19.94,-57.29 L 115 -57.29");

      g.append("svg:path")

         .attr("d", "M19.94,95.88 L 115 95.88");

    }(g.append("g")));

    (function (g) {

      g.attr("stroke", "#F0F0F3")

       .attr("stroke-width", 0.2)

       .attr("class", "guide xgridlines yfixed");

      g.append("svg:path")

         .attr("d", "M83.31,5 L 83.31 59.12");

      g.append("svg:path")

         .attr("d", "M51.62,5 L 51.62 59.12");

    }(g.append("g")));

  }(g.append("g")));

  (function (g) {

    d3.select("defs")

.append(“svg:clipPath”)

.attr("id", parent_id + "_clippath1")

.append("svg:path")

  .attr("d", " M19.94,5 L 115 5 115 59.12 19.94 59.12 z");g.attr("clip-path", "url(#" + parent_id + "_clippath1)");

    (function (g) {

      g.attr("class", "plotpanel");

      (function (g) {

        g.attr("class", "geometry");

        (function (g) {

          g.attr("fill", "#00BFFF")

           .attr("stroke", "#0096DD");

          g.append("svg:circle")

            .attr("cx", 99.16).attr("cy", 46.1).attr("r", 0.6)

          ;

        }(g.append("g")));

        (function (g) {

          g.attr("stroke-width", 0.3)

           .attr("stroke", "#0096DD");

          g.append("svg:path")

             .attr("d", "M93.87,7.81 L 104.44 7.81");

        }(g.append("g")));

        (function (g) {

          g.attr("stroke-width", 0.3)

           .attr("stroke", "#0096DD");

          g.append("svg:path")

             .attr("d", "M93.87,37.17 L 104.44 37.17");

        }(g.append("g")));

        (function (g) {

          g.attr("stroke-width", 0.3)

           .attr("stroke", "#0096DD");

          g.append("svg:path")

             .attr("d", "M99.16,20.57 L 99.16 7.81");

        }(g.append("g")));

        (function (g) {

          g.attr("stroke-width", 0.3)

           .attr("stroke", "#0096DD");

          g.append("svg:path")

             .attr("d", "M99.16,29.19 L 99.16 37.17");

        }(g.append("g")));

        (function (g) {

          g.attr("fill", "#00BFFF")

           .attr("stroke", "#0096DD")

           .attr("stroke-width", 0.3);

          g.append("svg:path")

             .attr("d", "M83.81,29.19 L 114.5 29.19 114.5 20.57 83.81 20.57 z");

        }(g.append("g")));

        (function (g) {

          g.attr("stroke-width", 0.3)

           .attr("stroke", "#0096DD");

          g.append("svg:path")

             .attr("d", "M62.19,19.3 L 72.75 19.3");

        }(g.append("g")));

        (function (g) {

          g.attr("stroke-width", 0.3)

           .attr("stroke", "#0096DD");

          g.append("svg:path")

             .attr("d", "M62.19,46.1 L 72.75 46.1");

        }(g.append("g")));

        (function (g) {

          g.attr("stroke-width", 0.3)

           .attr("stroke", "#0096DD");

          g.append("svg:path")

             .attr("d", "M67.47,28.23 L 67.47 19.3");

        }(g.append("g")));

        (function (g) {

          g.attr("stroke-width", 0.3)

           .attr("stroke", "#0096DD");

          g.append("svg:path")

             .attr("d", "M67.47,37.17 L 67.47 46.1");

        }(g.append("g")));

        (function (g) {

          g.attr("fill", "#00BFFF")

           .attr("stroke", "#0096DD")

           .attr("stroke-width", 0.3);

          g.append("svg:path")

             .attr("d", "M52.12,37.17 L 82.81 37.17 82.81 28.23 52.12 28.23 z");

        }(g.append("g")));

        (function (g) {

          g.attr("stroke-width", 0.3)

           .attr("stroke", "#0096DD");

          g.append("svg:path")

             .attr("d", "M30.5,34.61 L 41.06 34.61");

        }(g.append("g")));

        (function (g) {

          g.attr("stroke-width", 0.3)

           .attr("stroke", "#0096DD");

          g.append("svg:path")

             .attr("d", "M30.5,53.76 L 41.06 53.76");

        }(g.append("g")));

        (function (g) {

          g.attr("stroke-width", 0.3)

           .attr("stroke", "#0096DD");

          g.append("svg:path")

             .attr("d", "M35.78,42.27 L 35.78 34.61");

        }(g.append("g")));

        (function (g) {

          g.attr("stroke-width", 0.3)

           .attr("stroke", "#0096DD");

          g.append("svg:path")

             .attr("d", "M35.78,47.38 L 35.78 53.76");

        }(g.append("g")));

        (function (g) {

          g.attr("fill", "#00BFFF")

           .attr("stroke", "#0096DD")

           .attr("stroke-width", 0.3);

          g.append("svg:path")

             .attr("d", "M20.44,47.38 L 51.12 47.38 51.12 42.27 20.44 42.27 z");

        }(g.append("g")));

        (function (g) {

          g.attr("stroke-width", 0.6)

           .attr("stroke", "#34FFFF");

          g.append("svg:path")

             .attr("d", "M93.87,25.68 L 104.44 25.68");

        }(g.append("g")));

        (function (g) {

          g.attr("stroke-width", 0.6)

           .attr("stroke", "#34FFFF");

          g.append("svg:path")

             .attr("d", "M62.19,33.34 L 72.75 33.34");

        }(g.append("g")));

        (function (g) {

          g.attr("stroke-width", 0.6)

           .attr("stroke", "#34FFFF");

          g.append("svg:path")

             .attr("d", "M30.5,44.83 L 41.06 44.83");

        }(g.append("g")));

      }(g.append("g")));

    }(g.append("g")));

  }(g.append("g")));

  (function (g) {

    d3.select("defs")

.append(“svg:clipPath”)

.attr("id", parent_id + "_clippath2")

.append("svg:path")

  .attr("d", " M19.94,5 L 115 5 115 59.12 19.94 59.12 z");g.attr("clip-path", "url(#" + parent_id + "_clippath2)");

    (function (g) {

      g.attr("stroke", "none")

       .attr("class", "guide zoomslider")

       .attr("opacity", 0.00);

      (function (g) {

        g.attr("stroke", "#6A6A6A")

         .attr("stroke-opacity", 0.00)

         .attr("stroke-width", 0.3)

         .attr("fill", "#EAEAEA")

         .on("click", zoomin_behavior(ctx))

.on(“dblclick”, function() { d3.event.stopPropagation(); })

.on(“mouseover”, zoomslider_button_mouseover(“#cd5c5c”))

.on(“mouseout”, zoomslider_button_mouseover(“#6a6a6a”))

;

        g.append("svg:path")

           .attr("d", "M108,8 L 112 8 112 12 108 12 z");

        (function (g) {

          g.attr("fill", "#6A6A6A")

           .attr("class", "button_logo");

          g.append("svg:path")

             .attr("d", "M108.8,9.6 L 109.6 9.6 109.6 8.8 110.4 8.8 110.4 9.6 111.2 9.6 111.2 10.4 110.4 10.4 110.4 11.2 109.6 11.2 109.6 10.4 108.8 10.4 z");

        }(g.append("g")));

      }(g.append("g")));

      (function (g) {

        g.attr("fill", "#EAEAEA")

         .on("click", zoomslider_track_behavior(ctx, 82, 99));

        g.append("svg:path")

           .attr("d", "M88.5,8 L 107.5 8 107.5 12 88.5 12 z");

      }(g.append("g")));

      (function (g) {

        g.attr("fill", "#6A6A6A")

         .attr("class", "zoomslider_thumb")

         .call(zoomslider_behavior(ctx, 82, 99))

.on(“mouseover”, zoomslider_thumb_mouseover(“#cd5c5c”))

.on(“mouseout”, zoomslider_thumb_mouseover(“#6a6a6a”))

;

        g.append("svg:path")

           .attr("d", "M97,8 L 99 8 99 12 97 12 z");

      }(g.append("g")));

      (function (g) {

        g.attr("stroke", "#6A6A6A")

         .attr("stroke-opacity", 0.00)

         .attr("stroke-width", 0.3)

         .attr("fill", "#EAEAEA")

         .on("click", zoomout_behavior(ctx))

.on(“dblclick”, function() { d3.event.stopPropagation(); })

.on(“mouseover”, zoomslider_button_mouseover(“#cd5c5c”))

.on(“mouseout”, zoomslider_button_mouseover(“#6a6a6a”))

;

        g.append("svg:path")

           .attr("d", "M84,8 L 88 8 88 12 84 12 z");

        (function (g) {

          g.attr("fill", "#6A6A6A")

           .attr("class", "button_logo");

          g.append("svg:path")

             .attr("d", "M84.8,9.6 L 87.2 9.6 87.2 10.4 84.8 10.4 z");

        }(g.append("g")));

      }(g.append("g")));

    }(g.append("g")));

  }(g.append("g")));

}(g.append("g")));

}(g.append(“g”)));

}(g.append(“g”)));

d3.select(parent_id)

  .selectAll("path")

  .each(function() {

      var sw = parseFloat(window.getComputedStyle(this).getPropertyValue("stroke-width"));

      d3.select(this)

        .attr("vector-effect", "non-scaling-stroke")

        .style("stroke-width", sw + "mm");

  });

}

var data = [

];

var draw = function(parent_id) {

draw_with_data(data, parent_id);

};

if (‘undefined’ !== typeof module) {

module.exports = draw;

} else if (‘undefined’ !== typeof window) {

window.draw = draw

}

</script>

<script charset="utf-8">

    draw("#gadflyplot90");

</script>

© gepuro 2013

Slideshare Icon from here , Home Icon from icons8