内部数据来源
Julia 表格数据结构
VegaLite.jl
涵盖了 julia 生态系统中的大多数表格数据结构: DataFrames.jl
,JuliaDB.jl
,IndexedTables.jl
,各种文件IO库(CSVFiles.jl
,FeatherFiles.jl
,ExcelFiles.jl
,StatFiles.jl
,ParquetFiles.jl
)以及 Query.jl
中的表格形式。
管道操作数据
using VegaLite, VegaDatasets, Query
cars = dataset("cars");
cars |>
@vlplot(
:point,
x=:Horsepower,
y=:Miles_per_Gallon
)
上面的写法等价于 @vlplot(:point, data=cars, x=”Horsepower:q”, y=”Miles_per_Gallon:q”)
cars |> # 绘制日本地区的情况
@filter(_.Origin=="Japan") |>
@vlplot(
:point,
x={:Horsepower, scale={zero=false}},
y=:Miles_per_Gallon)
# 上面的写法等价于
cars |>
@vlplot(
:point,
transform=[{filter="datum.Origin == 'Japan'"}],
x={:Horsepower, scale={zero=false}},
y=:Miles_per_Gallon)
外部数据来源
主要是从 本地文件路径 和 网络 获得数据。这一部分功能目前还不完善。
参见:http://fredo-dedup.github.io/VegaLite.jl/stable/userguide/data.html#Referencing-external-data-1
using FilePaths
# path = p"folder/filename.csv";
# path |> @vlplot(:point, x=:a, y=:b)
上面的命令运行报错,估计功能还没实现。推荐将数据读取进来,然后进行管道操作 ↓
using CSV
data = CSV.read("data/data.csv") # 笔记 3 中的数据
a | b | |
---|---|---|
1 | A | 28 |
2 | B | 55 |
3 | C | 43 |
4 | D | 91 |
5 | E | 81 |
6 | F | 53 |
7 | G | 19 |
8 | H | 87 |
9 | I | 52 |
data |> @vlplot(:text, x={:a, axis=nothing}, y={:b, title=nothing}, text=:a, color=:a)
data |> @vlplot(:text, x="b:o", y={:b, title=nothing}, text=:a, color=:a)