Chapter 6. Data Visualization in Julia
import Pkg;
Pkg.add(["Tidier", "TidierData", "TidierText", "TidierStrings", "TidierPlots", "DataFrames", "CSV", "Pipelines", "Makie", "StatsPlots", "RDatasets"]);
using Tidier, TidierData, TidierText, TidierStrings, TidierPlots, DataFrames, CSV, Pipelines, Makie, StatsPlots, RDatasets
import Makie.IntervalsBetween, Makie.Attributes
TidierPlots_set("plot_log", false) # I don't not want to see many logs
TidierPlots_set("plot_show", false) # and repetitive plots in VSCode
[32m[1m Resolving[22m[39m package versions...
[32m[1m No Changes[22m[39m to `~/.julia/environments/v1.11/Project.toml`
[32m[1m No Changes[22m[39m to `~/.julia/environments/v1.11/Manifest.toml`
false
Load Data
df = dataset("datasets", "iris")
first(df, 5)
5×5 DataFrame
Row
SepalLength
SepalWidth
PetalLength
PetalWidth
Species
Float64
Float64
Float64
Float64
Cat…
1
5.1
3.5
1.4
0.2
setosa
2
4.9
3.0
1.4
0.2
setosa
3
4.7
3.2
1.3
0.2
setosa
4
4.6
3.1
1.5
0.2
setosa
5
5.0
3.6
1.4
0.2
setosa
Basic Plots
1. Scatter Plot
ggplot(data=df) +
geom_point(@aes(x = PetalLength, y = PetalWidth)) +
labs(x="Petal Length", y="Petal Width") +
theme_minimal()

2. Bar Plot
ggplot(data=df) +
geom_bar(@aes(x = PetalWidth)) +
labs(x="Petal Width") +
theme_minimal()

3. Line Plot
ggplot(data=df, @aes(x = PetalLength, y = PetalWidth)) +
geom_line() +
labs(x="Petal Length", y="Petal Width") +
theme_minimal()

4. Histogram
ggplot(data=df, @aes(x = PetalWidth)) +
geom_histogram() +
labs(x="Petal Width") +
theme_minimal()

Color and themes
1. Color
ggplot(data=df, @aes(x = PetalLength, y = PetalWidth, color = SepalWidth)) +
geom_point() +
labs(x="Petal Length", y="Petal Width") +
theme_minimal()

2. Themes
ggplot(data=df, @aes(x = PetalLength, y = PetalWidth, color = SepalWidth)) +
geom_point() +
labs(x="Petal Length", y="Petal Width") +
theme_latexfonts()

Facet
ggplot(data=df, @aes(x = PetalLength, y = PetalWidth, color = SepalWidth)) +
geom_point() +
facet_wrap("Species") +
labs(x="Petal Length", y="Petal Width") +
theme_latexfonts()

However, the supports of ggplot-like visualization cannot be identical to that of ggplot2
in R
.
If you want to use R packages or Python packages for certain purposes, we can also simply use them in Julia
PreviousChatpter 5 (cont.). Advanced Causal Inference in JuliaNextChapter 7. Using R and Python in Julia
Last updated
Was this helpful?