Tweeted twitter.com/StackMma/status/915315085073174530
7 added 166 characters in body
source | link

Final outcome addressing all the requirements above should look like:

enter image description here

Final outcome addressing all the requirements above should look like:

enter image description here

6 Response to @kglr's answer. Looking for clarification.
source | link


Ideal

The following code outlines a more ideal solution, allowing for users to alter various parameters, change the cutoff, and specify points to highlight via the corresponding option.

This does not work. I think it either has something to do with Module, or the explicit use of the parameters...

Options[BoxWhiskerDistributionChart] = {"InternalOpacity" -> 0.7, 
   "PointsToHighlight" -> {}, "PointToHighlightColor" -> Black, 
   "UpperCutoff" -> .75, "LowerCutoff" -> .25, 
   "EdgeColor" -> Charting`ChartStyleInformation["Color"] };
BoxWhiskerDistributionChart[{{xmin_, xmax_}, {ymin_, ymax_}}, values_,
   metadata_, OptionsPattern[]] :=
 Module[
  {chartParameters = {{{xmin, xmax}, {ymin, ymax}}, values, metadata}},
  {

     (*Give boxes thick edges with their respective color*)

     EdgeForm[{Thick, OptionValue["EdgeColor"]}],
     (*Alter boxes internal opacity with their respective color*)

      FaceForm[
      Opacity[OptionValue["InternalOpacity"], 
       Charting`ChartStyleInformation["Color"]]],

     (*Use smooth density to change box shape, 
     with given quantile cutoffs*)

     ChartElementDataFunction["SmoothDensity"][chartParameters] /. 
      GeometricTransformation[Polygon[x_, y___], transformation_] :> 
       Polygon[
        DeleteCases[
         AffineTransform[transformation]@
          x, {_, _?((# < 
                Quantile[values, OptionValue["LowerCutoff"]] || # > 
                Quantile[values, OptionValue["UpperCutoff"]]) &)}], y],
     Opacity[1],

     (*Color points also foudn in the PointsToHighlight option*)

     ChartElementDataFunction["PointDensity", 
        "PointStyle" -> PointSize[Medium]][chartParameters] /. 
      GraphicsGroup[{x_, y__}] :> ({y} /. 
         Point[p_] :> (({If[
                MemberQ[OptionValue["PointsToHighlight"], #[[2]]], 
                OptionValue["PointToHighlightColor"]], Point[{#}]} & /@
              p))),

     (*Remove the default BoxWhiskerChart EdgeForm*)
     EdgeForm[],
     (*Remove the default BoxWhiskerChart FaceForm*)
     FaceForm[],
     (*Produce the plot*)

     System`BarFunctionDump`boxplot[][chartParameters]
     } &;
  ]


Ideal

The following code outlines a more ideal solution, allowing for users to alter various parameters, change the cutoff, and specify points to highlight via the corresponding option.

This does not work. I think it either has something to do with Module, or the explicit use of the parameters...

Options[BoxWhiskerDistributionChart] = {"InternalOpacity" -> 0.7, 
   "PointsToHighlight" -> {}, "PointToHighlightColor" -> Black, 
   "UpperCutoff" -> .75, "LowerCutoff" -> .25, 
   "EdgeColor" -> Charting`ChartStyleInformation["Color"] };
BoxWhiskerDistributionChart[{{xmin_, xmax_}, {ymin_, ymax_}}, values_,
   metadata_, OptionsPattern[]] :=
 Module[
  {chartParameters = {{{xmin, xmax}, {ymin, ymax}}, values, metadata}},
  {

     (*Give boxes thick edges with their respective color*)

     EdgeForm[{Thick, OptionValue["EdgeColor"]}],
     (*Alter boxes internal opacity with their respective color*)

      FaceForm[
      Opacity[OptionValue["InternalOpacity"], 
       Charting`ChartStyleInformation["Color"]]],

     (*Use smooth density to change box shape, 
     with given quantile cutoffs*)

     ChartElementDataFunction["SmoothDensity"][chartParameters] /. 
      GeometricTransformation[Polygon[x_, y___], transformation_] :> 
       Polygon[
        DeleteCases[
         AffineTransform[transformation]@
          x, {_, _?((# < 
                Quantile[values, OptionValue["LowerCutoff"]] || # > 
                Quantile[values, OptionValue["UpperCutoff"]]) &)}], y],
     Opacity[1],

     (*Color points also foudn in the PointsToHighlight option*)

     ChartElementDataFunction["PointDensity", 
        "PointStyle" -> PointSize[Medium]][chartParameters] /. 
      GraphicsGroup[{x_, y__}] :> ({y} /. 
         Point[p_] :> (({If[
                MemberQ[OptionValue["PointsToHighlight"], #[[2]]], 
                OptionValue["PointToHighlightColor"]], Point[{#}]} & /@
              p))),

     (*Remove the default BoxWhiskerChart EdgeForm*)
     EdgeForm[],
     (*Remove the default BoxWhiskerChart FaceForm*)
     FaceForm[],
     (*Produce the plot*)

     System`BarFunctionDump`boxplot[][chartParameters]
     } &;
  ]
5 added 3432 characters in body
source | link

Update: Combining DistributionChart and BoxWhiskerChart

Now we add the points with this chuck:

ChartElementDataFunction["PointDensity", 
   "PointStyle" -> PointSize[Medium]][##] /. 
 GraphicsGroup[{x_, y__}] :> ({y} /. 
    Point[p_] :> (({If[MemberQ[class, #[[2]]], col], Point[{#}]} & /@ 
        p)))

Again we can rewrite parts of it:

ChartElementDataFunction["PointDensity", 
   "PointStyle" -> PointSize[Medium]][parameters] /. 
 GraphicsGroup[{x_, y__}] :> ({y} /. 
    Point[p_] :> (({If[MemberQ[class, #[[2]]], col], Point[{#}]} & /@ 
        p)))

This code isolates which points are of interest and changes their color. However I do not find this code straight forward with two delayed rules and replacement.

So if someone can explain this to me? All of it.


The next two lines, are called to overwrite the "PointDensity" Edge and Face Forms.

While I see that it works. Why do we have to recall them? Can't we just assign them prior to PointDensity and only take the Points?


and the last line is best summed up by @kglr:

Finally, SystemBarFunctionDumpboxplot[] produces the basic box-whisker graphics objects in BoxWhiskerChart, and the modification I made is to add the directives EdgeForm[] and FaceForm[]

Although I do not know why we have to call that context... Is there a way to do this without getting into contexts?

Combining DistributionChart and BoxWhiskerChart

Update: Combining DistributionChart and BoxWhiskerChart

Now we add the points with this chuck:

ChartElementDataFunction["PointDensity", 
   "PointStyle" -> PointSize[Medium]][##] /. 
 GraphicsGroup[{x_, y__}] :> ({y} /. 
    Point[p_] :> (({If[MemberQ[class, #[[2]]], col], Point[{#}]} & /@ 
        p)))

Again we can rewrite parts of it:

ChartElementDataFunction["PointDensity", 
   "PointStyle" -> PointSize[Medium]][parameters] /. 
 GraphicsGroup[{x_, y__}] :> ({y} /. 
    Point[p_] :> (({If[MemberQ[class, #[[2]]], col], Point[{#}]} & /@ 
        p)))

This code isolates which points are of interest and changes their color. However I do not find this code straight forward with two delayed rules and replacement.

So if someone can explain this to me? All of it.


The next two lines, are called to overwrite the "PointDensity" Edge and Face Forms.

While I see that it works. Why do we have to recall them? Can't we just assign them prior to PointDensity and only take the Points?


and the last line is best summed up by @kglr:

Finally, SystemBarFunctionDumpboxplot[] produces the basic box-whisker graphics objects in BoxWhiskerChart, and the modification I made is to add the directives EdgeForm[] and FaceForm[]

Although I do not know why we have to call that context... Is there a way to do this without getting into contexts?

4 added 3432 characters in body
source | link
3 added 1 character in body; edited title
source | link
2 edited tags
| link
1
source | link