Data Visualization Examples
•
|
Begin by loading the Statistics package.
|
|
Combining Visualizations
|
|
>
|
A := <5, 2, 5, 8, 4, 5, 10, 5>:
|
>
|
B := map(t -> t-.5, A):
|
>
|
P := ColumnGraph(A, legend = ["Data Set A"]):
|
>
|
Q := LineChart(B, color = red, thickness = 3, symbol = circle, symbolsize = 10, legend = ["Data Set B"]):
|
|
Superimpose the two plots and display the result.
|
>
|
plots[display](P, Q, title = "Bar Chart and Line Chart", axis[2] = [gridlines = [7, thickness = 2, linestyle = dash, color = white]]);
|
|
|
Pie Chart
|
|
>
|
T := <a, b, c, a, a, b, a, a, a, b, b, c, c, 1, 2, 3, a, 1>:
|
>
|
PieChart(T, sector = 0..180, color = red..yellow);
|
|
|
Sampling from the Beta Distribution
|
|
>
|
X := RandomVariable(NonCentralBeta(1, 2, 3)):
|
>
|
P := BoxPlot(S, orientation = horizontal, offset = -.6, width = .1, deciles = false):
|
>
|
R := DensityPlot(X, range = 0..1, thickness = 3):
|
>
|
plots[display](P, Q, R, gridlines = true);
|
|
Use a probability plot to compare a sample distribution and the original distribution.
|
|
|
Exploring Data Sets
|
|
|
You can use the Explore command to interactively explore characteristics of datasets, such as point density using the ScatterPlot and SunflowerPlot commands:
|
>
|
Y := Vector( [Sample( RandomVariable(Normal(0, 1)), 200 ), Sample( RandomVariable(Normal(2.6, 1)), 200 )] ):
|
>
|
Z := Vector( [Sample( RandomVariable(Normal(0, 1)), 200 ), Sample( RandomVariable(Normal(2.6, 1)), 200 )] ):
|
>
|
ExcisePoints := proc( fractionexcised, dataset1, dataset2, plottype )
uses Statistics;
local plotopts;
plotopts := view = [min(dataset1)..max(dataset1), min(dataset2)..max(dataset2)];
`if`( plottype = "SunflowerPlot",
SunflowerPlot( Excise(evalf[3](fractionexcised), dataset1, dataset2 ), plotopts ),
ScatterPlot( Excise(evalf[3](fractionexcised), dataset1, dataset2 ), plotopts ) );
end proc:
|
>
|
Explore( ExcisePoints( fractionexcised, Y, Z, plottype ),
parameters = [[plottype = ["ScatterPlot","SunflowerPlot"], label = ` `, placement = bottom],
[ fractionexcised = -1.0 .. 1.0, label = `Fraction Excised` ] ],
initialvalues = [fractionexcised = 0],
title = "Excising Data" );
|
|
Note: Before interacting with this interactive example, you need to execute the code. (Either execute the entire worksheet, or execute the first command to load the package and then execute all the commands in this Exploring Data Sets section.)
|
Return to Index for Example Worksheets
|
|