Skip to content

Commit fd67dc8

Browse files
committed
add other marks to user guid
1 parent 0bd80c6 commit fd67dc8

File tree

11 files changed

+436
-1
lines changed

11 files changed

+436
-1
lines changed

docs/gallery/Plots/Band/band.jl

Lines changed: 64 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,64 @@
1+
# ---
2+
# title: Band plot
3+
# id: demo_band_plot1
4+
# description: Using the `Band` mark to produce area plots
5+
# cover: assets/band_plot1.svg
6+
# ---
7+
8+
# `Band` allows users to produce Band plot. The plot mark needs a coordinate and lower and upper values.
9+
10+
using InMemoryDatasets, DLMReader, StatisticalGraphics
11+
12+
svg("assets/band_plot1.svg", sgplot(Dataset(x=-5:5, y=-(-5:5).^2, y2=(-5:5).^2 .+ 5), [Band(x=:x, lower=:y, upper=:y2, thickness=2, interpolate=:basis), RefLine(values=[0], axis=:yaxis)], width=100, height=100, xaxis=Axis(translate=0,offset=0, grid=true, griddash=[3]), yaxis=Axis(translate=0, grid=true, offset=0, griddash=[3]))) #hide #md
13+
14+
15+
ds = Dataset(
16+
x = 1:4,
17+
y = rand(4),
18+
y2 = rand(4) .+ 5
19+
)
20+
21+
sgplot(ds, Band(x=:x, lower=:y, upper=:y2))
22+
23+
24+
# Combining with other plots
25+
26+
dubai_weather = filereader(joinpath(dirname(pathof(StatisticalGraphics)),
27+
"..", "docs", "assets", "dubai_weather.csv"),
28+
types=Dict(1 =>Date))
29+
30+
sgplot(
31+
dubai_weather,
32+
[
33+
Band(x=:date, lower=:min, upper=:max),
34+
Line(x=:date, y=:min, color="#4682b4", thickness=1),
35+
Line(x=:date, y=:max, color="#ff7f0e", thickness=0.5),
36+
Line(x=:date, y=:pressure, color="#2ca02c", y2axis=true, breaks=true),
37+
Scatter(x=:date, y=:pressure, outlinecolor="#2ca02c", size=10, y2axis=true)
38+
],
39+
xaxis=Axis(offset=10, type=:date, grid=true, griddash=[1, 1], title="Date"),
40+
yaxis=Axis(offset=10, grid=true, griddash=[1, 1], title="Temperature(°C)"),
41+
y2axis=Axis(offset=10, title="Pressure")
42+
)
43+
44+
45+
# **unemployment stacked area plot across industries**
46+
47+
# Reproducing an example from the [`vega`](https://vega.github.io)`s examples collection.
48+
49+
unemployment = filereader(joinpath(dirname(pathof(StatisticalGraphics)),
50+
"..", "docs", "assets", "unemployment_across_industry.csv"),
51+
types = Dict(2=>Date))
52+
53+
sort!(unemployment, :series, rev=true) # keep alphabetical order
54+
modify!(groupby(unemployment, :date), :count=>cumsum=>:cum_sum)
55+
sort!(unemployment, [:date,:cum_sum], rev=[false,true]) # put the larger areas behind the smaller one
56+
57+
sgplot(
58+
unemployment,
59+
Band(x=:date, lower=0.0, upper=:cum_sum, group=:series, opacity=1),
60+
nominal = [:series],
61+
xaxis=Axis(type=:time, nice=false),
62+
yaxis=Axis(title=""),
63+
groupcolormodel = Dict(:scheme=>"category20b"),
64+
)
Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
# ---
2+
# title: Bubble plot
3+
# id: demo_bubble1
4+
# description: Scatter plot with varying size
5+
# cover: assets/bubble1.svg
6+
# ---
7+
8+
using InMemoryDatasets, StatisticalGraphics, DLMReader, Chain
9+
10+
svg("assets/bubble1.svg", sgplot(filter(filereader(joinpath(dirname(pathof(StatisticalGraphics)),"..", "docs", "assets", "nations.csv"), emptycolname=true, quotechar='"'), :year, by = ==(2010))[1:3:150, :], Bubble(x=:gdpPercap,y=:lifeExp, size=:population, colorresponse=:region, labelfont="Times", labelsize=8, labelcolor=:group, thickness=0.1, maxsize=20, outlinecolor=:white), clip=false, xaxis=Axis(grid=true, domain=false, labelcolor=:white, titlecolor=:white, tickcolor=:white, gridcolor=:lightgray, gridthickness=0.2, offset=0, tickcount=10, type=:log), yaxis=Axis(grid=true, gridcolor=:lightgray,gridthickness=0.2, offset=0, tickcount=10,domain=false, labelcolor=:white, titlecolor=:white, tickcolor=:white), width=100, height=100, legend=false)) #hide #md
11+
12+
13+
# `Bubble` is similar to `Scatter`, however, user can pass a `size` column to `Buble`
14+
15+
ds = Dataset(rand(20, 3), :auto)
16+
17+
sgplot(ds, Bubble(x=:x1, y=:x2, size=:x3), clip=false)
18+
19+
20+
# `Bubble` support most of the keywords available to `Scatter`
21+
22+
nations = filereader(joinpath(dirname(pathof(StatisticalGraphics)),
23+
"..", "docs", "assets", "nations.csv"),
24+
emptycolname=true, quotechar='"')
25+
26+
@chain nations begin
27+
sort([:population, :continent], rev=[true, false]);
28+
filter(:year, by = ==(2010));
29+
sgplot(
30+
Bubble(x=:gdpPercap,
31+
y=:lifeExp,
32+
colorresponse=:region,
33+
colormodel=:category,
34+
size=:population,
35+
outlinecolor=:white,
36+
labelresponse=:country,
37+
labelsize=8,
38+
labelcolor=:colorresponse,
39+
maxsize=70,
40+
tooltip=true
41+
),
42+
clip=false,
43+
xaxis=Axis(type=:log, nice=false),
44+
)
45+
end
Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
# ---
2+
# title: Density
3+
# id: demo_density1
4+
# description: Drawing Density
5+
# cover: assets/density1.svg
6+
# ---
7+
8+
using InMemoryDatasets, DLMReader, StatisticalGraphics
9+
10+
y = rand([0, 2, 6], 100) #hide #md
11+
svg("assets/density1.svg", sgplot(Dataset(x=randn(100) .+ y, y=y), Density(x=:x, type=:kernel, group=:y), nominal=:y, legend=false, width=100, height=100, xaxis=Axis(translate=0,offset=0, grid=true, griddash=[3]), yaxis=Axis(translate=0, grid=true, offset=0, griddash=[3]))) #hide #md
12+
13+
14+
# `Density` can be used to fit a normal pdf or a kernel density to data. By default it used normal density.
15+
16+
ds = Dataset(x=rand(100))
17+
18+
sgplot(ds, Density(x=:x))
19+
20+
# Passing `type=:kernel` allows fitting a kernel Distributions
21+
22+
sgplot(ds, Density(x=:x, type=:kernel))
23+
24+
# `Density` like other plots allow `group`
25+
26+
iris = filereader(joinpath(dirname(pathof(StatisticalGraphics)),
27+
"..", "docs", "assets", "iris.csv"))
28+
29+
sgplot(iris,
30+
Density(x=:SepalLength, type=:kernel, group=:Species)
31+
)
32+
33+
# Users allow to combine `Density` and `Histogram`
34+
35+
ds = Dataset(x=randn(100));
36+
sgplot(
37+
ds,
38+
[
39+
Histogram(x=:x, color=:steelblue, outlinethickness=0.5, space=0.5),
40+
Density(x=:x, type=:kernel, color=:red, fillopacity=0.3),
41+
Density(x=:x, color=:green, fillopacity=0.3)
42+
],
43+
xaxis = Axis(offset=10, domain=false),
44+
yaxis = Axis(offset=10, domain=false, grid=true)
45+
)
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
# ---
2+
# title: Heatmap
3+
# id: demo_heatmap1
4+
# description: Drawing Heatmap (2D Histogram)
5+
# cover: assets/heat1.svg
6+
# ---
7+
8+
using InMemoryDatasets, DLMReader, StatisticalGraphics
9+
10+
svg("assets/heat1.svg", sgplot(Dataset(x=randn(1000),y=randn(1000)), Heatmap(x=:x, y=:y, xbincount=5, ybincount=5), width=100, height=100, xaxis=Axis(translate=0,offset=0, grid=true, griddash=[3]), yaxis=Axis(translate=0, grid=true, offset=0, griddash=[3]), legend=false)) #hide #md
11+
12+
# Example
13+
14+
ds = Dataset(x=randn(10000), y=randn(10000))
15+
16+
sgplot(ds, Heatmap(x=:x, y=:y))
17+
Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
# ---
2+
# title: Histogram
3+
# id: demo_histogram1
4+
# description: Drawing Histogram
5+
# cover: assets/hist1.svg
6+
# ---
7+
8+
using InMemoryDatasets, DLMReader, StatisticalGraphics
9+
10+
svg("assets/hist1.svg", sgplot(Dataset(x=randn(1000)), Histogram(x=:x, space=0), width=100, height=100, xaxis=Axis(translate=0,offset=0, grid=true, griddash=[3]), yaxis=Axis(translate=0, grid=true, offset=0, griddash=[3]))) #hide #md
11+
12+
13+
# `Histogram` draw histogram for given column.
14+
15+
ds = Dataset(x=randn(10000))
16+
17+
sgplot(ds, Histogram(x=:x))
18+
19+
# Assigning the `y` keyword argument, produce horizontal plot
20+
21+
sgplot(ds, Histogram(y=:x))
22+
23+
# By default `Histogram` compute pdf, however, user may pass `:cdf`, `:count`, ... or anyother for scaling the bars
24+
25+
sgplot(ds, Histogram(x=:x, scale=:cdf))
26+
27+
# Like other plots, `Histogram` support `group`,
28+
29+
iris = filereader(joinpath(dirname(pathof(StatisticalGraphics)),
30+
"..", "docs", "assets", "iris.csv"))
31+
32+
sgplot(iris,
33+
Histogram(x=:SepalLength, group=:Species, opacity=0.5)
34+
)
35+
36+
# Passing `midpoints` allows more control on bin selection
37+
38+
sgplot(iris,
39+
Histogram(x=:SepalLength,
40+
group=:Species,
41+
opacity=0.5,
42+
midpoints=3.5:.4:8
43+
)
44+
)
Lines changed: 73 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,73 @@
1+
# ---
2+
# title: Polygon
3+
# id: demo_polygon_plot1
4+
# description: Using the `Polygon` mark to draw simple polygons
5+
# cover: assets/polygon1.svg
6+
# ---
7+
8+
using InMemoryDatasets, StatisticalGraphics, Chain
9+
10+
ds=Dataset(x=[0,0,2,2,4,4,6,6,4,4,2,2,7,7,9,9], y=[0,10,10,6,6,10,10,0,0,4,4,0,0,10,10,0], id=[fill(1,12);fill(2,4)]) #hide #md
11+
12+
svg("assets/polygon1.svg", sgplot(ds, Polygon(x=:x, y=:y, id=:id, opacity=0.5), width=100, height=100, xaxis=Axis(offset=0, padding=10, grid=true), yaxis=Axis(offset=0, padding=10, grid=true))) #hide #md
13+
14+
15+
# `Polygon` can be used to draw polygons. Each polygon is represented by xy-coordinates and its id. `sgplot` produces a seperate polygon for each id.
16+
17+
ds=Dataset(
18+
x=[0,0,2,2,4,4,6,6,4,4,2,2,7,7,9,9],
19+
y=[0,10,10,6,6,10,10,0,0,4,4,0,0,10,10,0],
20+
id=[fill(1,12);fill(2,4)]
21+
)
22+
23+
sgplot(ds,
24+
Polygon(x=:x, y=:y, id=:id, opacity=0.5),
25+
xaxis=Axis(padding=10),
26+
yaxis=Axis(padding=10)
27+
)
28+
29+
# Users can pass `colorresponse` or `group` for colorful drawings
30+
31+
ds = Dataset(id = repeat(1:10, 3), x = rand(30), y=rand(30))
32+
33+
sgplot(ds, Polygon(x=:x, y=:y, id=:id, colorresponse=:id, opacity=0.7))
34+
35+
# `Polygon` can be customised by other keywords,
36+
37+
triangle(a, mul=[1,1,1]) = [(0.0, 0.0) .*
38+
mul[1], (sqrt(2 * a^2 - 2 * a^2 * cos(a)), 0.0) .* mul[2],
39+
((a^2 - a^2 * cos(a)) / sqrt(
40+
2 * a^2 - 2 * a^2 * cos(a)),
41+
(a^2 * sin(a)) / sqrt(2 * a^2 - 2 * a^2 * cos(a))) .* mul[3]
42+
]
43+
44+
ds = Dataset(x=range(0.01, 3, step=0.091))
45+
46+
@chain ds begin
47+
modify!(
48+
:x => byrow(x->x/10) => :opacity,
49+
:x => byrow(triangle) => :t1,
50+
:x => byrow(x->triangle(x, [(1,-1), (1,-1), (3.1,-1)])) => :t2
51+
)
52+
53+
flatten!(r"^t")
54+
55+
modify!(
56+
:t1 => splitter => [:x1, :y1],
57+
:t2 => splitter => [:x2, :y2]
58+
)
59+
sgplot(
60+
[
61+
Polygon(x="x$i", y="y$i",
62+
id=:x,
63+
opacityresponse=:opacity,
64+
color=:darkgreen,
65+
outline=false)
66+
for i in 1:2
67+
],
68+
height=200,
69+
width=800,
70+
xaxis=Axis(show=false),
71+
yaxis=Axis(show=false)
72+
)
73+
end

docs/gallery/Plots/Reg/reg.jl

Lines changed: 66 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,66 @@
1+
# ---
2+
# title: Regression line
3+
# id: demo_reg
4+
# description: Fitting regression lines to data
5+
# cover: assets/reg1.svg
6+
# ---
7+
8+
using InMemoryDatasets, StatisticalGraphics, DLMReader
9+
10+
# User can use `Reg` to draw regression lines fitted to data
11+
12+
iris = filereader(joinpath(dirname(pathof(StatisticalGraphics)),
13+
"..", "docs", "assets", "iris.csv"))
14+
15+
svg("assets/reg1.svg", sgplot(iris, Reg(x=2,y=1,group=5, clm=true, degree=3), clip=false, wallcolor=:lightgray, xaxis=Axis(grid=true, gridcolor=:white, offset=0), yaxis=Axis(grid=true, gridcolor=:white, offset=0), width=100, height=100, legend=false)) #hide #md
16+
17+
18+
sgplot(iris, Reg(x=:SepalLength, y=:SepalWidth))
19+
20+
# Use `Scatter` to add the scatter plot of data
21+
22+
sgplot(iris, [
23+
Reg(x=:SepalLength, y=:SepalWidth),
24+
Scatter(x=:SepalLength, y=:SepalWidth)
25+
],
26+
clip=false
27+
)
28+
29+
# Passing `degree` allows to control the degree of polynomial fitted to data
30+
31+
sgplot(iris, [
32+
Reg(x=:SepalLength, y=:SepalWidth, degree=3),
33+
Scatter(x=:SepalLength, y=:SepalWidth)
34+
],
35+
clip=false
36+
)
37+
38+
# `clm` and `cli` produce the confidence band (by default 95%) for mean and prediction, respectively
39+
40+
sgplot(iris, [
41+
Reg(
42+
x=:SepalLength, y=:SepalWidth,
43+
degree=3,
44+
clm=true,
45+
cli=true
46+
),
47+
Scatter(x=:SepalLength, y=:SepalWidth)
48+
],
49+
clip=false
50+
)
51+
52+
53+
# `group` is supported
54+
55+
sgplot(iris, [
56+
Reg(
57+
x=:SepalLength, y=:SepalWidth,
58+
degree=3,
59+
clm=true,
60+
cli=true,
61+
group=:Species
62+
),
63+
Scatter(x=:SepalLength, y=:SepalWidth)
64+
],
65+
clip=false
66+
)

docs/gallery/Plots/Segment/segment.jl

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,8 @@ sgplot(cars_sum,
3434
Scatter(y=:Origin, x=r"^max", symbol=:stroke, angle=90)
3535
],
3636
xaxis=Axis(title="Acceleration", padding=10),
37-
yaxis=Axis(padding=.5)
37+
yaxis=Axis(padding=.5),
38+
width=200
3839
)
3940

4041
# `Segment` like other plots accept `group`.
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
# ---
2+
# title: TextPlot
3+
# id: demo_text1
4+
# description: Put text on a graph
5+
# cover: assets/text1.svg
6+
# ---
7+
8+
using InMemoryDatasets, DLMReader, StatisticalGraphics
9+
10+
svg("assets/text1.svg", sgplot(Dataset(x=[1,2,3], y=[1,2,3], text='A':'C'), TextPlot(x=:x, y=:y, text=:text), width=100, height=100, xaxis=Axis(translate=0,offset=0, grid=false, griddash=[3], padding=10), yaxis=Axis(translate=0, grid=false, padding=10, offset=0, griddash=[3]), legend=false, clip=false)) #hide #md
11+
12+
# Example
13+
14+
ds = Dataset(x=rand(10), y=rand(10), text='A':'J')
15+
16+
sgplot(ds, TextPlot(x=:x, y=:y, text=:text))

0 commit comments

Comments
 (0)