Hoogle Search
Within LTS Haskell 24.52 (ghc-9.10.3)
Note that Stackage only displays results for the latest LTS and Nightly snapshot. Learn more.
errorCall :: String -> Selector ErrorCallhspec-expectations-pretty-diff Test.Hspec.Expectations.Pretty No documentation available.
-
hvega Graphics.Vega.Tutorials.VegaLite Vega-Lite supports a number of data transformations, including several "pre-canned" transformations, such as a kernel-density estimator, which I will use here to look for structure in the parallax distribution. The earlier use of a fixed-bin histogram - parallaxHistogram and ylogHistogram - showed a peak around 5 to 10 milli-arcseconds, and a secondary one around 20 to 25 milli-arcseconds, but can we infer anything more from the data? I have already shown that the transform function works in a similar manner to encoding, in that it is applied to one or more transformations. In this example I use the density transform - which is new to Vega Lite 4 - to "smooth" the data without having to pre-judge the data (although there are options to configure the density estimation). The transform creates new fields - called "value" and "density" by default - which can then be displayed as any other field. In this case I switch from Bar or Line to use the Area encoding, which fills in the area from the value down to the axis. Open this visualization in the Vega Editor
let trans = transform . density "plx" [] enc = encoding . position X [ PName "value" , PmType Quantitative , PAxis [ AxTitle "parallax" ] ] . position Y [ PName "density", PmType Quantitative ] in toVegaLite [ gaiaData , mark Area [ MOpacity 0.7 , MStroke "black" , MStrokeDash [ 2, 4 ] , ] , trans [] , enc [] ]
The parallax distribution shows multiple peaks within the 5 to 10 milli-arcsecond range, and separate peaks at 12 and 22 milli-arcseconds. The properties of the area mark are set here to add a black, dashed line around the edge of the area. The DashStyle configures the pattern by giving the lengths, in pixels, of the "on" and "off" segments, so here the gaps are twice the length of the line segments. This was done more to show that it can be done, rather than because it aids this particular visualization! densityParallaxGrouped :: VegaLitehvega Graphics.Vega.Tutorials.VegaLite The density estimation can be configured using DensityProperty. Here we explicitly label the new fields to create (rather than use the defaults), and ensure the calculation is done per cluster. This means that the data range for each cluster is used to perform the KDE, which in this case is useful (as it ensures the highest fidelity), but there are times when you may wish to ensure a consistent scale for the evaluation (in which case you'd use the DnExtent option, as well as possibly DnSteps, to define the grid). The final change is to switch from density estimation to counts for the dependent axis. Open this visualization in the Vega Editor
let trans = transform . density "plx" [ DnAs "xkde" "ykde" , DnGroupBy [ "Cluster" ] , DnCounts True ] enc = encoding . position X [ PName "xkde" , PmType Quantitative , PAxis [ AxTitle "Parallax" ] ] . position Y [ PName "ykde" , PmType Quantitative , PAxis [ AxTitle "Counts" ] ] . color [ MName "Cluster" , MmType Nominal ] in toVegaLite [ gaiaData , mark Area [ MOpacity 0.7 ] , trans [] , enc [] ]
Note how the clusters separate out in pretty cleanly, but - as also shown in the pointPlot visualization below - it is pretty busy around 7 milli arcseconds. The counts here (the Y axis) are significantly larger than seen than the actual count of stars, shown in starCount. It appears that the DnCounts True option is interpreted as multiplying the density values by the number of values in a group, which means that there is a bin-width effect. This is explored further in the compareCounts plot below.-
hvega Graphics.Vega.Tutorials.VegaLite The stripPlotWithColor visualization can be changed to show two variables just by adding a second position declaration, which shows that the 7 milli-arcsecond range is rather crowded: Open this visualization in the Vega Editor
let enc = encoding . position X [ PName "plx", PmType Quantitative, PAxis [ AxTitle "Parallax (mas)" ] ] . position Y [ PName "Cluster", PmType Nominal ] . color [ MName "Cluster", MmType Nominal ] in toVegaLite [ gaiaData , mark Tick [] , enc [] ]
I have left the color-encoding in, as it makes it easier to compare to stripPlotWithColor, even though it replicates the information provided by the position of the mark on the Y axis. The yHistogram example below shows how the legend can be removed from a visualization. -
hvega Graphics.Vega.Tutorials.VegaLite With simpleHistogram it becomes easy to get a histogram of the parallax values: Open this visualization in the Vega Editor
parallaxHistogram = simpleHistogram "plx"
We can see that although parallaxes around 20 to 25 milli-arcseconds dominated the earlier visualizations, such as stripPlotWithColor, most of the stars have a much-smalled parallax, with values in the range 5 to 10. -
hvega Graphics.Vega.Tutorials.VegaLite In this example I compare the parallax values
- as the raw distribution, using the ticks display we saw in the very first plot, stripPlot, (although with a few adjustments)
- against a smoothed version of the distribution, calculated using the regression transform (e.g. densityParallax).
let plxScale = PScale [ SType ScLog , SNice (IsNice False) , SDomain (DNumbers [3, 30]) ] opacityEnc ounsel osel = opacity [ MSelectionCondition (SelectionName selName) [ MNumber osel ] [ MNumber ounsel ] ] tickEnc = encoding . position X [ PName "plx" , PmType Quantitative , plxScale , PAxis [ AxTitle "Parallax (mas)" ] ] . color [ MName "Cluster" , MmType Nominal , MLegend [] ] . opacityEnc 0.05 0.3 plotWidth = width 600 tickLayer = asSpec [ plotWidth , tickEnc [] , mark Tick [ ] ] densTrans = transform . density "plx" [ DnGroupBy [ "Cluster" ] , DnAs "value" "density" ] densEnc = encoding . position X [ PName "value" , PmType Quantitative , plxScale , PAxis [ AxNoTitle , AxLabels False ] ] . position Y [ PName "density" , PmType Quantitative , PAxis [ AxTitle "Density" ] ] . color [ MName "Cluster" , MmType Nominal , MLegend [ LOrient LOBottom , LTitleAnchor AMiddle , LTitle "Select a cluster" ] , MScale [ SScheme "category10" [] ] ] . opacityEnc 0.3 1 densLayer = asSpec [ plotWidth , densTrans [] , densEnc [] , sel [] , mark Line [ ] ] selName = "legend" sel = selection . select selName Single [ BindLegend (BLField "Cluster") ] in toVegaLite [ gaiaData , spacing 0 , bounds Flush , vConcat [ densLayer, tickLayer ] ]
I have also changed the color scheme to "category10", which isn't necessarily any better than the default ("tableau10"), but is at least different (I was hoping to get a better separation in color space for the IC2391 and IC2602 clusters, but quickly gave up after trying out a few options). Here is the visualization after selecting the label "NGC2451" in the legend: -
hvega Graphics.Vega.Tutorials.VegaLite Our first attempt is with the column function, which tells Vega-Lite to create a plot for each Cluster field (and introduces us to the F family of FacetChannel constructors). The legend has been turned off with MLegend [], since it doesn't add anything to this visulization (as the individual plots, labelled by the cluster name, provide the same information). Open this visualization in the Vega Editor
let enc = encoding . position X [ PName "Gmag", PmType Quantitative, PBin [] ] . position Y yAxis . color [ MName "Cluster", MmType Nominal, MLegend [] ] . column [ FName "Cluster", FmType Nominal ] yAxis = [ PAggregate Count , PmType Quantitative , PAxis [ AxTitle "Number of Stars" ] ] in toVegaLite [ gaiaData , mark Bar [] , enc [] ]
Since we have nine clusters in the sample, the overall visualization is too wide, unless you have a very-large monitor. Can we do better? -
hvega Graphics.Vega.Tutorials.VegaLite The number of columns used in small-multiple can be defined using the columns function. However, this requires us to:
- move the facet definition out from the encoding and into the top-level, with the facetFlow function;
- and define the plot as a separate specification, and apply it with specification and asSpec.
let enc = encoding . position X [ PName "Gmag", PmType Quantitative, PBin [] ] . position Y yAxis . color [ MName "Cluster", MmType Nominal, MLegend [] ] yAxis = [ PAggregate Count , PmType Quantitative , PAxis [ AxTitle "Number of Stars" ] ] in toVegaLite [ gaiaData , columns 4 , facetFlow [ FName "Cluster", FmType Nominal ] , specification (asSpec [ mark Bar [], enc [] ]) ]
Open this visualization in the Vega Editor Note that Vega Lite does support a "facet" field in its encodings, but hvega follows Elm VegaLite and requires you to use this wrapped facet approach. I chose 4 columns rather than 3 here to show how "empty" plots are encoded. You can see how a 3-column version looks in the next plot, densityMultiples. -
hvega Graphics.Vega.VegaLite All the rows and columns are of the same size (this is based on the maximum subview size).
-
hvega Graphics.Vega.VegaLite No documentation available.