Skip to content

Commit fd0c91c

Browse files
committed
more documentation about sgpanel
1 parent fd67dc8 commit fd0c91c

File tree

4 files changed

+245
-1
lines changed

4 files changed

+245
-1
lines changed

docs/make.jl

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,10 @@ makedocs(
2929
"Usage" => [
3030
scatter
3131
],
32+
"Multiple panels" => [
33+
"Panel" => "man/panel.md",
34+
"Grid" => "man/grid.md"
35+
],
3236
"Interactive" => [
3337
"Pyramid" => "man/pyramid.md",
3438
"Nations" => "man/nations.md",

docs/src/index.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
# StatisticalGraphics.jl
22

3-
Welcome to the StatisticalGraphics.jl documentation!
3+
Welcome to the [StatisticalGraphics.jl](https://github.com/sl-solution/StatisticalGraphics.jl) documentation!
44

55
This resource aims to teach you everything you need to know to get up and running with the `StatisticalGraphics.jl` package.
66

docs/src/man/grid.md

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
# Introduction
2+
3+
The `sggrid` function positions a collection of Plots within a grid.
4+
5+
## Example
6+
7+
```@example
8+
using InMemoryDatasets, StatisticalGraphics
9+
10+
ds = Dataset(x=randn(100), y=randn(100));
11+
h_x = sgplot(ds, Histogram(x=:x, space=0), xaxis=Axis(show=false), yaxis=Axis(show=false), height=200);
12+
h_y = sgplot(ds, Histogram(y=:y, space=0), xaxis=Axis(show=false), yaxis=Axis(show=false), width=200);
13+
xy = sgplot(ds, Scatter(x=:x, y=:y), xaxis=Axis(domain=false), yaxis=Axis(domain=false));
14+
15+
sggrid(h_x, sggrid(xy, h_y), columns=1)
16+
```

docs/src/man/panel.md

Lines changed: 224 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,224 @@
1+
# Introduction
2+
3+
When a grouped data set is passed as the first argument of `sgplot`, a multiple panel graph is produced for each group of observations. Four types of layout can be used to arrange the produced plots.
4+
5+
## Panel
6+
7+
Plots are put side by side. user can control how many rows or column should be produced.
8+
9+
### Example
10+
11+
```@example
12+
13+
using InMemoryDatasets, StatisticalGraphics
14+
15+
panel_example = Dataset(rand(1:4, 1000, 10), :auto)
16+
17+
sgplot(
18+
groupby(panel_example, [:x5, :x6]),
19+
Pie(category=:x7,
20+
label=:both,
21+
labelsize=8,
22+
innerradius=0.4
23+
),
24+
width = 100,
25+
height = 100,
26+
columns=5,
27+
legend=false
28+
)
29+
```
30+
31+
```@example
32+
using InMemoryDatasets, DLMReader, StatisticalGraphics, Chain
33+
34+
movies = filereader(joinpath(dirname(pathof(StatisticalGraphics)),
35+
"..", "docs", "assets", "movies.csv"),
36+
dlmstr="::")
37+
@chain movies begin
38+
delete("Major Genre", by = contains("Concert"), missings=false)
39+
groupby("Major Genre")
40+
sgplot(
41+
[
42+
Scatter(x="Rotten Tomatoes Rating", y="IMDB Rating", size=10),
43+
Reg(
44+
x="Rotten Tomatoes Rating", y="IMDB Rating",
45+
degree=3,
46+
clm=true,
47+
)
48+
],
49+
xaxis=Axis(grid=true,gridcolor=:white),
50+
yaxis=Axis(grid=true,gridcolor=:white),
51+
height=200,
52+
width=200,
53+
columns=4,
54+
columnspace=15,
55+
rowspace=15,
56+
headercolname=false,
57+
headeroffset=-20,
58+
headercolor=:white,
59+
headersize=20,
60+
headeritalic=true,
61+
wallcolor=:lightgray,
62+
clip=false
63+
)
64+
end
65+
```
66+
67+
68+
## Lattice
69+
70+
This layout is supported when two columns are selected to group data. One column will be used as the row column and the other one as the column.
71+
72+
### Example
73+
74+
Passing `layout=:lattice` change the default layout to `lattice`
75+
76+
77+
```@example
78+
using InMemoryDatasets, StatisticalGraphics
79+
80+
panel_example = Dataset(rand(1:4, 1000, 10), :auto)
81+
sgplot(
82+
gatherby(panel_example, [:x3, :x4]),
83+
Bar(x=:x1, group=:x2),
84+
nominal = [:x2],
85+
layout = :lattice,
86+
width = 100,
87+
height = 100
88+
)
89+
```
90+
91+
```@example
92+
using InMemoryDatasets, StatisticalGraphics
93+
94+
fun_example = Dataset(rand(1:4, 1000, 4), :auto)
95+
sgplot(
96+
gatherby(fun_example, [:x3, :x4]),
97+
Bar(x=:x1, group=:x2, barcorner=15),
98+
nominal = :x2,
99+
layout = :lattice,
100+
rowspace=5,
101+
columnspace=5,
102+
width = 100,
103+
height = 100,
104+
wallcolor=:lightgray,
105+
showheaders = false,
106+
xaxis=Axis(show=false),
107+
yaxis=Axis(show=false),
108+
legend=false,
109+
clip=false
110+
)
111+
```
112+
113+
## Row
114+
115+
When one column is used to group data, this option can be used to put graphs in a row layout.
116+
117+
To produce a row layout, user must pass `layout=:row`
118+
119+
### Examples
120+
121+
```@example
122+
using InMemoryDatasets, DLMReader, StatisticalGraphics
123+
124+
cars = filereader(joinpath(dirname(pathof(StatisticalGraphics)),
125+
"..", "docs", "assets", "cars.csv"),
126+
types = Dict(9=>Date))
127+
make_fmt(x) = split(x)[1]
128+
setformat!(cars, :Name => make_fmt)
129+
sgplot(
130+
groupby(cars, :Cylinders),
131+
Bar(response=:Horsepower, x=:Name,
132+
stat=IMD.mean,
133+
colorresponse=:Acceleration,
134+
colorstat=IMD.mean,
135+
orderresponse=:Horsepower,
136+
orderstat=IMD.maximum,
137+
outlinethickness=0.5,
138+
space=0,
139+
colormodel=["#d53e4f", "#fc8d59", "#fee08b", "#e6f598", "#99d594"]
140+
),
141+
142+
layout = :row,
143+
columnspace = 5,
144+
linkaxis=:y,
145+
proportional=true,
146+
147+
stepsize=15,
148+
xaxis=Axis(title="Make", angle=-90, baseline=:middle, align=:right, ticksize=0, domain=false, titlepadding=20),
149+
yaxis=Axis(title="Horsepower", domain=false),
150+
151+
headercolname = false,
152+
headersize=12,
153+
headerfontweight=900,
154+
155+
height=400,
156+
)
157+
```
158+
159+
## Column
160+
161+
When one column is used to group data, this option can be used to put graphs in a column layout.
162+
163+
To produce a row layout, user must pass `layout=:column`
164+
165+
**[U-District Cuisine Example](https://vega.github.io/vega/examples/u-district-cuisine/)**
166+
167+
Reproducing an example from the [`vega`](https://vega.github.io)`s examples collection.
168+
169+
```@example
170+
using InMemoryDatasets, DLMReader, StatisticalGraphics
171+
172+
udistrict = filereader(joinpath(dirname(pathof(StatisticalGraphics)),
173+
"..", "docs", "assets", "udistrict.csv"))
174+
# contains some information - use to customise the appearance
175+
udistrict_info = filereader(joinpath(dirname(pathof(StatisticalGraphics)),
176+
"..", "docs", "assets", "udistrict_info.csv"),
177+
quotechar='"')
178+
179+
# order data
180+
leftjoin!(udistrict, udistrict_info, on = :key)
181+
sort!(udistrict, :order)
182+
183+
# actual graph
184+
sgplot(
185+
gatherby(udistrict, :names),
186+
187+
Density(x=:lat, type=:kernel, bw=0.0005, npoints=200,
188+
scale=(x; samplesize, args...)->x .* samplesize, # to match the scale in the original example
189+
190+
group=:names,
191+
grouporder=:data,
192+
193+
fillopacity=0.7,
194+
color=:white
195+
),
196+
yaxis=Axis(show=false),
197+
xaxis=Axis(title="",
198+
grid=true,
199+
griddash=[2],
200+
values=([47.6516, 47.655363, 47.6584, 47.6614, 47.664924, 47.668519], ["Boat St.", "40th St.", "42nd St.", "45th St.", "50th St.", "55th St."])
201+
),
202+
203+
layout=:column,
204+
width=800,
205+
height=70,
206+
rowspace=-50, # to force overlaps
207+
panelborder=false,
208+
209+
headercolname=false,
210+
headerangle=0,
211+
headerloc=:start,
212+
headeralign=:left,
213+
214+
# set the font for the whole graph
215+
font="Times",
216+
italic=true,
217+
fontweight=100,
218+
219+
# change default colors
220+
groupcolormodel=udistrict_info[:, :color],
221+
222+
legend=false
223+
)
224+
```

0 commit comments

Comments
 (0)