Julia ć§ēµ±čØč§£ęćē¬¬ 6 ē« ćę°å¤ćć¼ćæć®åÆč¦åĀ¶
Version()
ęę°ćć¼ćøć§ć³ 2024-10-29 14:05
using Plots
default(
titlefont = (12, "times"),
guidefont = (10, "times"),
tickfont = (7, "times"),
label = "",
foreground_color_legend = nothing,
markerstrokewidth = 0,
grid = false,
tick_direction = :out,
alpha = 0.4
)
1 å¤éć®ć°ć©ćč”Øē¤ŗć«ćÆļ¼ćć¹ćć°ć©ć ļ¼histogramļ¼ć代č”ØēćŖćć®ć§ććć
2 å¤éć®ć°ć©ćč”Øē¤ŗć§ćÆę£åøå³ćäø»ćŖćć®ć§ććć
Julia ć§ć°ć©ćč”Øē¤ŗćććå “åļ¼Plots
ććć±ć¼ćøćä½æēØććććććÆćØć³ććÆ GR ćä½æēØććććØć«ććć
using Plots
gr()
Plots.GRBackend()
é£ē¶å¤ę°ļ¼ę°å¤ļ¼ćć¼ćæćØćć¦ćÆļ¼R ćēØęćć¦ćććć¼ćæć»ććć®ćć”ć® airquality
ćć¼ćæć»ćććēØćć¦ä¾ē¤ŗććć
using RCall
airquality = rcopy(R"airquality");
println("size: ", size(airquality))
first(airquality, 5)
size: (153, 6)
Row | Ozone | Solar_R | Wind | Temp | Month | Day |
---|---|---|---|---|---|---|
Int64? | Int64? | Float64 | Int64 | Int64 | Int64 | |
1 | 41 | 190 | 7.4 | 67 | 5 | 1 |
2 | 36 | 118 | 8.0 | 72 | 5 | 2 |
3 | 12 | 149 | 12.6 | 74 | 5 | 3 |
4 | 18 | 313 | 11.5 | 62 | 5 | 4 |
5 | missing | missing | 14.3 | 56 | 5 | 5 |
Ozone, Solar_R ćÆę¬ ęå¤ćå«ćć®ć§åćę±ćć«ę³Øęćåæ č¦ć§ććć
ćć¹ćć°ć©ć Ā¶
ćć¹ćć°ć©ć ćÆļ¼é£ē¶å¤ę°ć®ååøē¶ę³ćęę”ććć®ć«å½¹ē«ć¤ć
äøęØę¬ć®å “åĀ¶
ę¬ ęå¤ćå«ćå “åļ¼skipmissing()
ć§ćÆćŖćļ¼filter(!ismissing,...)
ćä½æććŖććć°ćŖććŖćć
x = filter(!ismissing, airquality.Ozone)
histogram(x)
ē¹ć«ä½ćęå®ććŖććØļ¼äøé©åćŖć°ć©ćććå¾ćććŖćć
ęåćć histogram()
ć«å¼ę°ćäøććć°ćććļ¼Julia ć§ćÆļ¼äøåŗ¦ęćććć°ć©ćć«å¾ććé¢ę°ć«ććļ¼ę§ć
ćŖč¦ē“ ćå ćć¦ććććØćć§ććć
é¢ę°åć®ęå¾ć !
ć§ććććØć«ę³Øęćććć
xlabel!("Ozone")
ylabel!("Density")
title!("Histgram of Ozone")
åćé¢ę°ć§å 容ćå¤ę“ććććØćć§ććć
xlabel!("Ozone (ppb)")
direction=:horizontal
ćęå®ććć°ę°“å¹³ćć¹ćć°ć©ć ć«ćŖćć
histogram(x, direction=:horizontal)
ćć¹ćć°ć©ć ćęćéć®éē“ļ¼bin
ćØćå¼ć°ććļ¼ć®ęå®ę³ćÆä½éććććć
- éē“ę°ćę“ę°ć§ęå®ćć
- ććÆćć«
- ć·ć³ćć«ļ¼
:auto
(Freedman-Diaconis),:sturges
,:sqrt
,:rice
,:scott
,:fd
ļ¼
ććć©ć«ćć®čØå®ćÆå¤ćć®å “åļ¼é©åć§ćŖćććØćå¤ćć
仄äøć® 6 åć®ć°ć©ćć®ćć”ļ¼ćć¼ćæć®ååøē¶ę³ćęćé©åć«č”Øćć¦ććć®ćÆ fig.5 ć§ćććbins
ćÆććÆćć«ć§ęå®ććć0:10:maximum(x)
ćÆęćå·¦ć®éē“ć®å§ć¾ćć®å¤ć 0ļ¼éē“å¹
ć 10ļ¼ęå¾ć®éē“ćÆę大å¤ć¾ć§ćč”Øćć¦ććć
éē“ę°ć§ęå®ćć¦ćļ¼ćć®ćØććć®éē“ę°ć«ćÆćŖććŖćććØććććfig.4 ćÆ bins=15
ćęå®ćć¦ęćććå®éć®éē“ę°ćÆ 9 ć«ćŖćļ¼bins=10
ć§ęćć fig.3 ćØåćć«ćŖć£ćć
å¤ćć®å “åļ¼ććÆćć«ć§ęå®ććć®ćęćććć
ęēµēćŖéē“ę°ć fig.2 ć®ććć«å°ćŖćć¦ćļ¼fig.6 ć®ććć«å¤ćć¦ććć¼ćæć®ååøē¶ę³ćę£ććęę”ć§ććŖćć®ć§ä½éćććć£ć¦ćæććØććć
using Plots.PlotMeasures # ä½ē½ć®åä½ mm ćŖć©ćęå¹ć«ććććć«åæ
č¦
p1 = histogram(x, title="fig.1"); # bins=:auto,
p2 = histogram(x, bins=5, title="fig.2");
p3 = histogram(x, bins=10, title="fig.3");
p4 = histogram(x, bins=15, title="fig.4");
p5 = histogram(x, bins=0:10:maximum(x), title="fig.5");
p6 = histogram(x, bins=0:5:maximum(x), title="fig.6");
plot(p1, p2, p3, p4, p5, p6, layout=(2, 3), bottom_margin = 20px)
histogram() ć®ćć©ć”ć¼ćæ normalize ćÆēø¦č»øć®åä½ćå¤ććć
:none
ę£č¦åććŖćļ¼ććć©ć«ćļ¼ćé«ććÆåŗ¦ę°ćč”Øćć:pdf
ē·é¢ē©ć 1 ć«ćŖćććć«ę£č¦åćććé«ććÆćåŗ¦ę°/(100Ćéē“å¹ )ć:probability
bin
ć®é«ćć®åć 1 ć«ćŖćććć«ę£č¦åćććé«ććÆćåŗ¦ę°/ćµć³ćć«ćµć¤ćŗćć¤ć¾ćēøåƾåŗ¦ę°ć§ļ¼100 åććć°ćć¼ć»ć³ćć§ććć:density
bin
ć®é¢ē©ć®åć 1 ć«ćŖćććć«ę£č¦åćććéē“å¹ ćēćććŖćå “åć«é©ćć¦ćććéē“å¹ ćēććå “åćÆćåŗ¦ę°/éē“å¹ ćć§ććć
using Plots.PlotMeasures # ä½ē½ć®åä½ mm ćŖć©ćęå¹ć«ććććć«åæ
č¦
p1 = histogram(x, normalize=:none, bins=0:10:150, title="fig.a");
p2 = histogram(x, normalize=:pdf, bins=0:10:150, title="fig.b");
p3 = histogram(x, normalize=:probability, bins=0:10:150, title="fig.c");
p4 = histogram(x, normalize=:density, bins=vcat(0:10:100, 125, 150...), title="fig.d");
plot(p1, p2, p3, p4, layout=(2, 2), bottom_margin = 20px)
č¤ę°ęØę¬ć®å “åĀ¶
Plots ććć±ć¼ćøć® histogram()
ć§ćÆļ¼č¤ę°ęØę¬ć®ćć¹ćć°ć©ć ćÆéćåććč”Øē¤ŗććć§ććŖćć®ć§ļ¼ęØę¬ę°ćå¤ćå “åćÆäøé©åć§ćććć
ę¬ ęå¤ćé¤ćć¦ęå„ć® Ozone
ęø¬å®å¤ćć¼ćæć»ćććä½ćć
using DataFrames
ozone = dropmissing(select(airquality, [:Ozone, :Month]));
monthly = groupby(ozone, :Month);
using StatsPlots
histogram([monthly[i].Ozone for i in 1:2],
bins=0:10:130,
bar_position=:overlay,
)
ćć®ćććŖå “åć«ćļ¼åēÆć®ćććŖćµććććććęćę¹ę³ćä½æćććØćÆć§ććć
using Dates # ęć®č±å
using Plots.PlotMeasures # ä½ē½ć®åä½ mm ćŖć©ćęå¹ć«ććććć«åæ
č¦
subplots = Array{Any, 1}(undef, 5)
for i in 1:5
subplots[i] = histogram([monthly[i].Ozone ],
bins=0:10:150,
xlabel="Ozone(ppb)",
ylabel="Days",
title="$(monthname(i+4))",
)
end
plot(subplots[1], subplots[2], subplots[3], subplots[4], subplots[5],
bottom_margin = 20px)
StatsPlots
ććć±ć¼ćøć® groupedhist()
ćÆļ¼bar_position=:dodge
ć§ć°ć«ć¼ćåććććć¹ćć°ć©ć ļ¼bar_position=:stack
ć§ē©ćæäøććć¹ćć°ć©ć ćęćććØćć§ććć
ćŖćļ¼ę¬ ęå¤ćććå “åć«ćÆäŗåć«é¤å»å¦ēććć¦ćććŖććć°ćŖććŖćć
ęå®ć§ćććć¼ćÆć¼ćå¼ę°ćÆ histogram()
ćØć»ć¼åćć§ćććbins
ļ¼normed
ļ¼weights
ļ¼nbins
ļ¼edges
ļ¼bar_width
using StatsPlots
ozone = dropmissing(select(airquality, [:Ozone, :Month]));
@df ozone groupedhist(:Ozone, group=:Month, bar_position=:dodge, xlabel="Ozone")
@df airquality groupedhist(:Wind, group=:Month, bar_position=:stack,
xlabel="Wind")
@df airquality groupedhist(:Wind, group=:Month, bar_position=:stack)
ćććÆć¹ććććļ¼ē®±ć²ćå³ļ¼Ā¶
ćććÆć¹ćććććÆå„åćććÆć¹ć¢ć³ćć¦ć£ć¹ć«ć¼ļ¼ē®±ć²ćå³ļ¼ćØćććććļ¼äøå³ć«ē¤ŗććććŖå³ć§ćććäø央éØć®éć§å”ć£ćé·ę¹å½¢ļ¼ē®±ļ¼ć®äøč¾ŗććäøćć³ćøļ¼ē¬¬ 1 ååä½ę°ļ¼ $Q_1$ļ¼äøč¾ŗćäøćć³ćøļ¼ē¬¬ 3 ååä½ę°ļ¼$Q_3$ļ¼é·ę¹å½¢ć®äøć»ć©ć«ććē“ē·ćäøå¤®å¤ $Q_2$ ć§ćććäøäøć«ä¼øć³ć Tå/éTåć®ćććŖćć®ļ¼ć²ćļ¼ć®ęØŖę£éØåćÆć$Q_1 - 1.5IRQ$ććć大ććęå°ć®ćć¼ćæē¹ļ¼ć$Q_3 + 1.5IRQ$ćććå°ććę大ć®ćć¼ćæē¹ć§ććć$IRQ$ ćÆååēÆå² = $Q_3 - Q_1$ ć§ćććć²ćć®ę“ć«å¤å“ć«č”Øē¤ŗćććē¹ćÆļ¼å¤ćå¤ć§ććć
boxplot()
ć®ćć©ć”ć¼ćæćÆļ¼ä»„äøć®éćć
notch
ćč«ēå¤true
/false
ć§ęå®ććććÆć¹ććććć«åćč¾¼ćæļ¼ćććļ¼ćć¤ćććØćć«true
ćęå®ććļ¼ććć©ć«ććÆfalse
ļ¼ćwhisker_range
ćå®ę°ć§ęå®ćć²ććęććØćć«ä½æććć $IQR$ ć®åę°ļ¼ććć©ć«ććÆ 1.5ļ¼ććć®ēÆå²å¤ć®ćć¼ćæē¹ćÆå¤ćå¤ć§ćććoutliers
ćč«ēå¤true
/false
ć§ęå®ćå¤ćå¤ćęē»ćććØććÆtrue
ļ¼ććć©ć«ććÆtrue
ļ¼ćwhisker_width
ćå®ę°å¤/ć·ć³ćć«ć§ęå®ćć²ćć®ęØŖę£ć®é·ććē®±ć®å¹ ćØåććŖćć°:match
ļ¼ååćŖć:half
ļ¼ććć©ć«ććÆ:half
ļ¼ć
function fivenum!(x)
sort!(x)
n = length(x)
n4 = floor(Int, (n + 3) / 2) / 2
d = [n4, (n + 1) / 2, n + 1 - n4]
@. 0.5 * (x[floor(Int, d)] + x[ceil(Int, d)])
end
x = filter(!ismissing, airquality.Ozone);
# q1, median, q3 = quantile(x, [0.25, 0.5, 0.75])
q1, median, q3 = fivenum!(x) # q1, q3 ćÆććć³ćøććŖć®ć§ę£ē¢ŗć«ćÆćć”ććä½æć
IQR = q3 - q1
top = maximum(x[x .<= (q3+1.5IQR)])
bottom = minimum(x[x .>= (q1-1.5IQR)])
println("bottom = $bottom, q1 = $q1, median = $median, q3 = $q3, top = $top")
bottom = 1, q1 = 18.0, median = 31.5, q3 = 63.5, top = 122
using Plots
using Statistics
using StatsPlots
boxplot(x,
xticks=:none,
xlimit=(0.5, 1.8),
size=(300, 300))
annotate!(
(1.5, top, text("top", :left, :vcenter, 8)),
(1.5, q3, text("q3", :left, :vcenter, 8)),
(1.5, median, text("median", :left, :vcenter, 8)),
(1.5, q1, text("q1", :left, :vcenter, 8)),
(1.5, bottom, text("bottom", :left, :vcenter, 8)),
)
WARNING: using Statistics.median in module Main conflicts with an existing identifier.
ćććÆć¹ćććććÆč”Øē¤ŗćććå³ć®ę å ±éćå°ćŖćć®ć§ļ¼äøęØę¬ćć¼ćæć«ä½æćććććØćÆå°ćŖććå¤ćć®å “åćÆļ¼č¤ę°ęØę¬ć®ćć¼ćæć®ååøć®éććē¤ŗćććć«ä½æćććć
StatsPlots
ććć±ć¼ćøć® groupedboxplot()
ćę¬ ęå¤ć®ćććć¼ćæćÆäŗåć«é¤å»ćć¦ćććŖććć°ćŖććŖćć
using StatsPlots
ozone = dropmissing(select(airquality, [:Ozone, :Month]))
@df ozone groupedboxplot(:Month, :Ozone)
@df airquality groupedboxplot(:Month, :Wind)
ćć¤ćŖćŖć³ććććĀ¶
ćććÆć¹ćććććÆļ¼ē¬¬ 1 ååä½ę°ļ¼äø央å¤ļ¼ē¬¬ 3 ååä½ę°ćØļ¼å¤ćå¤ć®å¢ēå¤ļ¼ååä½ę°Ā±$1.5 IQR$ļ¼ććč”Øē¤ŗććŖćć
ćć¤ćŖćŖć³ćććććÆļ¼ćć³ć·ćć£ć¼ććććļ¼ć«ć¼ćć«åÆåŗ¦ęØå®å¤ļ¼ćč”Øē¤ŗććć®ć§ļ¼ćć¼ćæć®ååøē¶ę³ćććč©³ē“°ć«č”Øē¤ŗććććØćć§ććć
ååøå³ććććććć¤ćŖćŖć³ćŖć©ć®č„æę“å¼¦ę„½åØć«ä¼¼ć¦ććć®ć§ćć¤ćŖćŖć³ćććććØå¼ć°ćććļ¼ę„ę¬äŗŗēć«ćÆååØć®ć·ć«ćØććć®ććć«ćč¦ććć§ććććć
@df airquality violin(string.(:Month), :Wind, linewidth=0)
ååøć®ēå“ć ćč”Øē¤ŗććććØćć§ććļ¼side=:right
/:left
ļ¼ć®ć§ļ¼ćććéøć¹ć°ćć³ć·ćć£ć¼ććććć«č¦ćć¦ććć§ćććć
@df airquality violin(string.(:Month), :Wind, side=:right, linewidth=0)
ćććććććĀ¶
@df airquality dotplot(string.(:Month), :Wind, linewidth=0)
@df airquality dotplot(string.(:Month), :Wind, side=:right, linewidth=0)
ćć®ćććććććć§ćÆļ¼ćć¼ćæē¹ćéćŖććŖćććć«ć©ć³ćć ćŖę°å¤ļ¼Jitterļ¼ćå ćć¦ććć®ć§ļ¼ćć®äø¦ć³ć«ä½ććć®ęå³ćććććć«č¦ćć¦ćć¾ććPython ć® seaborn
ć«ćć swarmplot()
ć Julia ććä½æććććć«ćŖć£ć¦ćććļ¼ćććåćē¹č³Ŗćęć£ć¦ććć
ćć®ćććŖććØćéæććććć«
https://blog.goo.ne.jp/r-de-r/e/237f8bdfda925c5d724604aa9eabc8e3
ć«ććć°ć©ć ćåē¤ŗćć¦ććć
using FreqTables, Plots
function simple_dotplot(x, y; accu=0, stp=0, logflag=false, simple=false,
symmetrical=true, sizew=600, sizeh=400)
function logaxis(z)
pos = zeros(100)
minval = minimum(z)
maxval = maximum(z)
logmaxval = log10(maxval)
logminval = log10(minval)
width = logmaxval - logminval
factor = logmaxval < 3.5 ? 15 : 8
w = width / factor
st = floor(logminval)
delta = 10^st
ic = 0
while true
for i = 1:9
v = i * delta
if minval - delta <= v <= maxval + delta
if (i == 1 || ic == 0) || (ic > 0 && log10(v) - pos[ic] > w)
if i == 1 && ic > 0 && log10(v) - pos[ic] <= w
ic -= 1
end
ic += 1
pos[ic] = log10(v)
prev = v
end
end
end
delta *= 10
if delta > maxval
break
end
end
return ic > 3 ? pos[2:ic-1] : [logminval, median([logminval, logmaxval]), logmaxval]
end
if logflag == true
y0 = y
y = log10.(y);
end
minx = minimum(y)
maxx = maximum(y)
rng = maxx - minx
minx = minx - rng * 20 / sizeh
maxx = maxx + rng * 20 / sizeh
if accu == 0
accu = (maxx - minx) / 50
end
if stp == 0
stp = 30 / sizew
end
y = round.(y ./ accu, digits=0) * accu
table = freqtable(y, x)
yname, xname = names(table)
nvalue, ngroup = size(table)
# pyplot()
p = plot(tick_direction=:out, xticks=false, grid=false,
size=(sizew, sizeh), xlims = (0, length(xname)+1),
ylims=(minx, maxx), label="")
xticks!(1:ngroup, xname)
for i = 1:ngroup
for j = 1:nvalue
if table[j, i] != 0
n = table[j, i]
if n == 1
height, position = [yname[j]], [i]
else
height = repeat([yname[j]], n)
position = collect(range(i-stp*(n-1)/2, i+stp*(n-1)/2, length=n))
end
p = scatter!(position, height, labels="", alpha=0.7,
markercolor=i, markerstrokecolor=i)
end
end
end
if logflag
pos = logaxis(y0)
yticks!(pos, string.(round.(10 .^ pos, digits = 1)))
end
println("accu = $accu, stp = $stp")
# display(p)
p
end;
x = string.(airquality.Month); # åå¤ęćåæ
č¦
y = airquality.Wind;
simple_dotplot(x, y, accu=0.105, stp=0.05)
accu = 0.105, stp = 0.05
ć«ć¼ćć«åÆåŗ¦ęØå®ć®ęē»Ā¶
äøęØę¬ćć¼ćæć®ååøć«éććč¤ę°ęØę¬ć®ćć¼ćæć®ååøć®éććč”Øē¤ŗććć®ć«é©ćć¦ććć
density()
ćÆäŗåć« missing
å¦ēććć¦ćććŖććć°ćŖććŖćć
using StatsPlots
x = dropmissing(select(airquality, [:Ozone, :Month]))
@df x density(:Ozone, group = :Month)
xlabel!("Ozone")
ylabel!("Density")
using Dates
airquality.Monthname = monthname.(airquality.Month)
@df airquality density(:Wind, group = :Monthname)
xlabel!("Wind")
ylabel!("Density")
$Q-Q$ ććććĀ¶
$Q-Q$ ćććććÆļ¼ćć¼ćæć®ååøćę£č¦ååøćć©ćććē¢ŗčŖććććć«ēØććććć
qqnorm()
ćÆåćć£ć¦ę¬ ęå¤ćé¤å»ćć¦ćććć°ćŖććŖććć¾ćļ¼å¼ę°ćÆå®ę°ććÆćć«ć§ćŖććć°ćŖććŖćć®ć§ float()
ć§å®ę°åćć¦ćććć°ćŖććŖćć
qqline=:R
ćęå®ćććØļ¼R ć§ć®ććć©ć«ćć«å¾ćļ¼ęćē“ē·ćååøć® $Q_1$, $Q_3$ ćéćļ¼ć
x = float.(filter(!ismissing, airquality.Solar_R))
qqnorm(x)
qqnorm!(x, qqline=:R)
annotate!(330, 400, text("default", :blue, "times", 8))
annotate!(380, 360, text(":R", :green, "times", 8))
using Plots.PlotMeasures # ä½ē½ć®åä½ mm ćŖć©ćęå¹ć«ććććć«åæ
č¦")
using Distributions
p1 = qqnorm(airquality.Wind, title="p1")
p2 = qqplot(Normal, airquality.Wind, title="p2"); # qqnorm() ćØåć
p3 = qqnorm(airquality.Wind, qqline=:R, title="p3"); # R ćØåć
p4 = qqplot(Cauchy, airquality.Wind, title="p4"); # ē¬¬ 1 å¼ę°ć§ååøćęå®ć§ćć
plot(p1, p2, p3, p4, bottom_margin = 20px) # ćµćććććć®ććć ć®ä½ē½ xxpx)
WARNING: using Distributions.median in module Main conflicts with an existing identifier.
ę£åøå³Ā¶
ę£åøå³ćÆļ¼2 å¤ę°ć®ååøē¶ę³ćč”Øē¤ŗććć®ć«ęé©ć®ę¹ę³ć§ććć
scatter()
ćÆļ¼ę¬ ęå¤ missing
ćčŖåēć«é¤ćć
scatter(airquality.Ozone, airquality.Solar_R)
xlabel!("Ozone (ppb)")
ylabel!("Solar Radiation (lang)")
scatter()
ć®ćŖćć·ć§ć³ć§ļ¼smooth=true
ćØććććØć§ååø°ē“ē·ćčØå
„ć§ććć
scatter(airquality.Wind, airquality.Temp, smooth=true)
xlabel!("Wind (mph)")
ylabel!("Temperature (degrees F)")
ć°ć«ć¼ćå„ć«č²ććć¼ć«ć¼ćå¤ććć«ćÆļ¼
markercolor
ę“ę°å¤,:red
,:blue
,:green
,:brown
,:black
,:cyan
,:magenta
, ... http://juliagraphics.github.io/Colors.jl/stable/namedcolors/markershape
:none
,:auto
,:circle
,:rect
,:star5
,:diamond
,:+
,:x
,:hexagon
,:cross
,:xcross
,:utriangle
,:dtriangle
,:rtriangle
, ... https://docs.juliaplots.org/latest/generated/attributes_series/markersize
ę“ę°å¤ļ¼ććć©ć«ććÆ 4 ććÆć»ć«ļ¼
color2 = [:red, :blue, :cyan, :brown, :pink];
marker2 = [:circle, :rect, :star5, :diamond, :hexagon];
using Dates
p = scatter(airquality.Ozone, airquality.Solar_R,
markercolor=color2[airquality.Month.-4],
markershape=marker2[airquality.Month.-4],
xlims=(0, 170),
xlabel="Ozone",
ylabel="Solar_R",
label="")
for i in 1:5
scatter!([100], [120-20i], markercolor=color2[i], markershape=marker2[i], label="")
annotate!(105, 120-20i, text("$(monthname(i+4))", :left, 8), label="");
end
p
ć«ć¼ćć«åÆåŗ¦ęØå®Ā¶
å¤ę°ć®ć«ć¼ćć«åÆåŗ¦é¢ę°ćęØå®ććć
marginalkde()
ćÆļ¼ēé«ē·ćØå³ć®ę¬ä½äøéØćØå³ć«ććććć®å¤ę°ć®åØč¾ŗååøć®ć«ć¼ćć«åÆåŗ¦ćęćć
ę¬ ęå¤ćå«ćå “åćÆćŖć¹ććÆć¤ćŗé¤å»ćććć¼ćæćć¬ć¼ć ćä½æććļ¼ęē»ćć 2 å¤ę°ć§ćć¢ćÆć¤ćŗé¤å»ćć¦ä½æēØććć
using StatsPlots
df = dropmissing(select(airquality, [:Ozone, :Solar_R]))
marginalkde(df.Ozone, df.Solar_R)
ā Warning: Keyword argument `orientation` is deprecated. ā Please use `permute` instead. ā @ Plots ~/.julia/packages/Plots/kLeqV/src/args.jl:1552
missing
ććć¢ćÆć¤ćŗé¤å»ćććć¼ćæćć¬ć¼ć ć®ä½ćę¹ćÆä½éććććć
ć¾ćļ¼marginalkde()
ć«å¼ćē¶ćć¦ä»ć®ććććé¢ę°ćä½æēØććććØćć§ććć仄äøć®å³ćÆļ¼scatter!()
ć«ćććć¼ćæē¹ćčæ½å ććä¾ć§ććļ¼scatter()
ć§ćÆćŖćļ¼scatter!()
ć«ććŖććć°ćŖććŖćļ¼ćsubplot=2
ćÆęē»åÆ¾č±”ćå³ć®ę¬ä½éØåć§ććććØćē¤ŗććsmooth=true
ć«ććļ¼ååø°ē“ē·ćęē»ććć
using StatsPlots
df2 = dropmissing(DataFrame(x = airquality.Ozone, y = airquality.Solar_R))
marginalkde(df2.x, df2.y)
scatter!(df2.x, df2.y, subplot=2, smooth=true, linecolor=:black)
ę£åøå³č”åĀ¶
ę£åøå³č”åćÆļ¼č¤ę°ć®å¤ę°éć®ę£åøå³ćč”åē¶ć«é ē½®ćććććć¤ćć®é¢ę°ćććććććē¹å¾“ćęć£ć¦ććć
ćć¹ćć°ć©ć ć«ćććć1.2.3. č¤ę°ć®ć°ć©ććč”åē¶ć«ć¾ćØćć¦č”Øē¤ŗććę¹ę³ććåæēØćć¦ļ¼čŖåć§ęē»ććććØćć§ććć
ę¬ ęå¤ćÆäŗåć«é¤ćć¦ćććŖććć°ćŖććŖććdropmissing()
ć§ę¬ ęå¤ććŖć¹ććÆć¤ćŗé¤å»ćļ¼corrplot()
ć§ä½æēØććå¤ę°ćęå®ććć
corrplot()
ć®ē¬¬ 1 å¼ę°ćÆ $1Ćk$ č”åć§ććļ¼ććŖćć”ļ¼č¦ē“ ćć«ć³ćć§ćÆćŖćē©ŗē½ć§åŗåćļ¼ć
åå³ć® $x$ č»øļ¼$y$ č»øć©ćć«ćÆļ¼ććć©ć«ćć§ćć¼ćæćć¬ć¼ć ć®ååćä½æēØććććå„ć®ååć«ććććØććÆļ¼remane!()
/rename()
ć§ååćå¤ę“ćć¦ćććļ¼ē“ę„ label=["a" "b" "c" "d"]
ć®ććć«ååćē©ŗē½ć§åŗåć£ć¦ęå®ććć°ććć
using DataFrames
using StatsPlots
using RCall
airquality = rcopy(R"airquality")
first(airquality, 3)
Row | Ozone | Solar_R | Wind | Temp | Month | Day |
---|---|---|---|---|---|---|
Int64? | Int64? | Float64 | Int64 | Int64 | Int64 | |
1 | 41 | 190 | 7.4 | 67 | 5 | 1 |
2 | 36 | 118 | 8.0 | 72 | 5 | 2 |
3 | 12 | 149 | 12.6 | 74 | 5 | 3 |
airquality2 = dropmissing(airquality)
@df airquality2 corrplot([:Ozone :Solar_R :Wind :Temp], markersize=3, size=(600, 600))
cornerplot()
ćÆåå¤ę°ć®ćć¹ćć°ć©ć ćÆļ¼ę¬ä½ć®å³ć®äøćØå³ć«ęē»ćććć
ę¬ ęå¤ćÆäŗåć«é¤ćć¦ćććŖććć°ćŖććŖććselect()
ć§å¤ę°ćęå®ćć¦ļ¼dropmissing()
ć§ missing
ććŖć¹ććÆć¤ćŗé¤å»ćććć¼ćæćć¬ć¼ć ćä½ćć
cornerplot()
ć®ē¬¬ 1 å¼ę°ćÆćć¼ćæćć¬ć¼ć ć§ćÆćŖćč”åć§ćŖććbćŖććŖćć®ć§ļ¼Matrix()
ć§č”åćØćć¦ęå®ććć
åå³ć® $x$ č»øļ¼$y$ č»øć©ćć«ćÆļ¼label
å¼ę°ć§ęå®ććććć¼ćæćć¬ć¼ć ć®ååćä½æēØććå “åćÆ names()
ćęå®ćććå„ć®ååć«ććććØććÆļ¼remane!()
/rename()
ć§ååćå¤ę“ćć¦ćććļ¼ē“ę„ label=["a" "b" "c" "d"]
ć®ććć«ååćē©ŗē½ć§åŗåć£ć¦ęå®ććć°ććć
airquality3 = dropmissing(select(airquality, Not([:Month, :Day])));
cornerplot(Matrix(airquality3), label=names(airquality3), markersize=3, size=(600, 600))
ä½å³ć¬ć·ćĀ¶
äŗč»øć°ć©ćĀ¶
ęćē·ć°ć©ććØę£ć°ć©ććåęć«ęćä¾
using Plots, Plots.PlotMeasures
kion = [-3.0, -2.6, 2.5, 8.0, 15.7, 17.4, 21.7, 22.5, 19.3, 13.3, 3.9, -0.8];
kousuiryou = [86.0, 32.5, 39.0, 30.5, 29.5, 71.0, 31.5, 144.5, 108.5, 97.0, 82.0, 62.0];
tsuki = 1:12
#=
pyplot( grid=false,
tick_direction=:out,
xticks=1:12,
right_margin=15mm)
=#
gr( grid=false,
tick_direction=:out,
xticks=1:12,
right_margin=15mm,
fontfamily="IPAMincho",
foreground_color_legend = nothing)
plot( tsuki,
kion,
markershape=:circle,
color=:red,
ylabel="å¹³åę°ęø©ļ¼āļ¼",
label="å¹³åę°ęø©",
legend=:topleft)
bar!( twinx(),
tsuki,
kousuiryou,
alpha=0.3,
ylabel="éę°“éļ¼mmļ¼",
label="éę°“é",
legend=:topright)
GKS: could not find font IPAMincho.ttf GKS: glyph missing from current font: 24179 GKS: glyph missing from current font: 22343 GKS: glyph missing from current font: 27671 GKS: glyph missing from current font: 28201 GKS: glyph missing from current font: 65288 GKS: glyph missing from current font: 65289 GKS: glyph missing from current font: 24179 GKS: glyph missing from current font: 22343 GKS: glyph missing from current font: 27671 GKS: glyph missing from current font: 28201 GKS: glyph missing from current font: 65288 GKS: glyph missing from current font: 65289 GKS: glyph missing from current font: 24179 GKS: glyph missing from current font: 22343 GKS: glyph missing from current font: 27671 GKS: glyph missing from current font: 28201 GKS: invalid bitmap size GKS: glyph missing from current font: 38477 GKS: glyph missing from current font: 27700 GKS: glyph missing from current font: 37327 GKS: glyph missing from current font: 65288 GKS: glyph missing from current font: 65289 GKS: glyph missing from current font: 38477 GKS: glyph missing from current font: 27700 GKS: glyph missing from current font: 37327 GKS: glyph missing from current font: 65288 GKS: glyph missing from current font: 65289 GKS: glyph missing from current font: 38477 GKS: glyph missing from current font: 27700 GKS: glyph missing from current font: 37327 GKS: invalid bitmap size
Andrews plotĀ¶
å¤éØćŖć³ćÆ: StatsPlots Andrews ćććććÆļ¼å¤å¤éćåØęć®ē°ćŖćäøč§é¢ę°ć«å²ćå½ć¦ļ¼åä½ććØć«åęćććę²ē·ćęććä¼¼ćå¤ćåćåä½ćÆåććććŖę²ē·ć«ćŖćć®ć§ļ¼å Øä½ēć«ć©ć®ćććŖå¾åććć¤ćć®ćć©ććććååØćććć大ć¾ćć«ęććććØćć§ććć
仄äøć®ä½æēØä¾ć§ćÆļ¼setosa ćØ versicolor ćÆä¼¼ć¦ćććļ¼virginica ćÆć”ćć£ćØéćććØććććć
ćććļ¼ćć®ęč¦ćÆééć£ć¦ćććäøć®å³ć®å”ä¾ćéć£ć¦ććļ¼ććć°ć©ć ćäøå®å Øļ¼ļ¼č¶č²ć virginica, éć versicolor, ē·ć setosa ćŖć®ć§ļ¼ä»ć®åęęę³ć§å¾ććććvirginica ćØ versicolor ćÆä¼¼ć¦ćććļ¼setosa ćÆć”ćć£ćØéćććØććć®ćę£č§£ć§ććć
using RCall
iris = rcopy(R"iris");
using StatsPlots
@df iris andrewsplot(:Species, cols(1:4), legend = :topleft, alpha=0.4)
include("andrewsgraph.jl");
y = Matrix(iris[:, 1:4])
# setosa: 1, blue, vercicolor: 2, red, virginica: 3, green
# col = transpose(vcat(fill(1, 50), fill(2, 50), fill(3, 50)))
col = repeat(1:3, inner=50)'
andrewsgraph(y, normalize=false, col=col)
andrewsgraph(y, normalize=true, col=col)
ęåŗ§ć°ć©ćĀ¶
include("constellationgraph.jl");
dat = Matrix(iris[:, 1:4])
col = vcat(fill(1, 50), fill(2, 50), fill(3, 50))
constellationgraph(dat, col=col)
ćµć³ćć©ćÆć¼ććććĀ¶
# import Pkg; Pkg.add("CategoricalArrays")
include("sunflowerplot.jl");
x = round.(3randn(500) .+ 10, digits=0);
y = round.(3randn(500) .+ 10, digits=0);
sunflowerplot(x, y, color=:gold, rotate=true)
p1 = sunflowerplot(iris.Sepal_Length[1:50], iris.Sepal_Width[1:50], color=:blue, r=0.07, rotate=true);
p2 = sunflowerplot(iris.Sepal_Length[51:100], iris.Sepal_Width[51:100], color=:green, r=0.07, initialize=false, rotate=true);
p3 = sunflowerplot(iris.Sepal_Length[101:150], iris.Sepal_Width[101:150], color=:red, r=0.07, initialize=false, rotate=true);
p3
ć¬ć¼ćć¼ćć£ć¼ćĀ¶
include("radar.jl");
using RCall
swiss = rcopy(R"swiss");
first(swiss, 10)
Row | Fertility | Agriculture | Examination | Education | Catholic | Infant_Mortality |
---|---|---|---|---|---|---|
Float64 | Float64 | Int64 | Int64 | Float64 | Float64 | |
1 | 80.2 | 17.0 | 15 | 12 | 9.96 | 22.2 |
2 | 83.1 | 45.1 | 6 | 9 | 84.84 | 22.2 |
3 | 92.5 | 39.7 | 5 | 5 | 93.4 | 20.2 |
4 | 85.8 | 36.5 | 12 | 7 | 33.77 | 20.3 |
5 | 76.9 | 43.5 | 17 | 15 | 5.16 | 20.6 |
6 | 76.1 | 35.3 | 9 | 7 | 90.57 | 26.6 |
7 | 83.8 | 70.2 | 16 | 7 | 92.85 | 23.6 |
8 | 92.4 | 67.8 | 14 | 8 | 97.16 | 24.9 |
9 | 82.4 | 53.3 | 12 | 7 | 97.67 | 21.0 |
10 | 82.9 | 45.2 | 16 | 13 | 91.38 | 24.4 |
test = swiss[1:5, 2:6]
test
Row | Agriculture | Examination | Education | Catholic | Infant_Mortality |
---|---|---|---|---|---|
Float64 | Int64 | Int64 | Float64 | Float64 | |
1 | 17.0 | 15 | 12 | 9.96 | 22.2 |
2 | 45.1 | 6 | 9 | 84.84 | 22.2 |
3 | 39.7 | 5 | 5 | 93.4 | 20.2 |
4 | 36.5 | 12 | 7 | 33.77 | 20.3 |
5 | 43.5 | 17 | 15 | 5.16 | 20.6 |
radar(test)
radar(test, col=[:black, :red, :green4, :blue, :brown])
radar(test, maxx=[50, 20, 20, 100, 23], normalize=false,
col=[:black, :red, :green4, :blue, :brown])
radar(test, maxx=[50, 20, 20, 100, 23],
minx=[10, 0, 0, 0, 20], normalize=false,
col=[:black, :red, :green4, :blue, :brown])
radar(test, maxx=100, minx=0, normalize=false,
col=[:black, :red, :green4, :blue, :brown])