Skip to content

Instantly share code, notes, and snippets.

{
"$schema": "https://vega.github.io/schema/vega/v5.json",
"background": "white",
"padding": 5,
"width": 1000,
"height": 500,
"title": {
"text": "The political history reflected by 120 years of Summer Olympics",
"frame": "group"
},
year country medal
1 1896 Other Countries in Europe 68
2 1900 Other Countries in Americas 9
3 1900 Other Countries in Asia 2
4 1900 Other Countries in Europe 130
5 1900 Other Countries in Oceania 1
6 1904 Other Countries in Americas 53
7 1904 Other Countries in Europe 15
8 1906 Other Countries in Americas 2
9 1906 Other Countries in Europe 240
library(ggplot2)
library(gganimate)
library(gifski)
g7 <- ggplot(brics, aes(gdp, medal, size = population, colour = country)) +
geom_point(show.legend = TRUE, alpha = 0.7) +
scale_size(range = c(2, 9)) +
scale_x_log10() +
theme_bw() +
labs(title = 'Year: {round(({frame_time}-1992)/4)*4+1992}', x = 'GDP', y = 'The number of gold medal') +
transition_time(year) +
country medal gdp year
Brazil 2 400599250000 1992
Canada 6 592387689252.916 1992
China 16 426915712711.146 1992
France 8 1401465923172.24 1992
Germany 33 2131571696931.75 1992
India 0 288208430383.964 1992
Italy 6 1320161645718.77 1992
Japan 3 3908809463463.86 1992
Russia 45 460290556900.726 1992
date county state fips cases deaths
3/28/2020 Autauga Alabama 1001 6 0
3/28/2020 Baldwin Alabama 1003 10 0
3/28/2020 Blount Alabama 1009 5 0
3/28/2020 Bullock Alabama 1011 3 0
3/28/2020 Butler Alabama 1013 1 0
3/28/2020 Calhoun Alabama 1015 3 0
3/28/2020 Chambers Alabama 1017 17 0
3/28/2020 Cherokee Alabama 1019 1 0
3/28/2020 Chilton Alabama 1021 7 0
date state fips cases deaths
3/28/2020 Alabama 1 720 4
3/28/2020 Alaska 2 102 1
3/28/2020 Arizona 4 773 15
3/28/2020 Arkansas 5 409 5
3/28/2020 California 6 5565 121
3/28/2020 Colorado 8 2061 44
3/28/2020 Connecticut 9 1524 33
3/28/2020 Delaware 10 214 5
3/28/2020 District of Columbia 11 342 4
mpg disp hp drat wt qsec
Mazda RX4 21 160 110 3.9 2.62 16.46
Mazda RX4 Wag 21 160 110 3.9 2.875 17.02
Datsun 710 22.8 108 93 3.85 2.32 18.61
Hornet 4 Drive 21.4 258 110 3.08 3.215 19.44
Hornet Sportabout 18.7 360 175 3.15 3.44 17.02
Valiant 18.1 225 105 2.76 3.46 20.22
Duster 360 14.3 360 245 3.21 3.57 15.84
Merc 240D 24.4 146.7 62 3.69 3.19 20
Merc 230 22.8 140.8 95 3.92 3.15 22.9
@hawleylin
hawleylin / vega_exercise 4
Created March 25, 2020 16:21
Using the data at https://vda-lab.github.io/assets/stad_2910.json, create two linked plots: one with the network, and a scatterplot with community on the x-axis and the hadm_id on the y-axis. Your result should be similar to the visualisation below, and highlight points between the two plots on hover (check by hovering over the points).
{
"$schema": "https://vega.github.io/schema/vega/v5.json",
"description": "Assignment 4th graph",
"padding": 0,
"autosize": "none",
"width": 800,
"height": 400,
"signals": [
{"name": "cx", "update": "width / 1.4"},
@hawleylin
hawleylin / vega-lite_exercise 3
Created March 25, 2020 16:20
Make another interesting plot using this data.
{
"$schema": "https://vega.github.io/schema/vega-lite/v4.json",
"description": "Assignment 3rd graph",
"width": 400,
"height": 400,
"padding": 5,
"data": {
"url": "https://raw.githubusercontent.com/vda-lab/vda-lab.github.io/master/assets/station_366.json"
},
@hawleylin
hawleylin / vega-lite_exercise 2
Created March 25, 2020 16:18
Make a plot with the relative positions of the start stations vis-a-vis the end station, when that end station is 336. Show the end station itself as well. Your plot could look like this: (see tutorial)
{
"$schema": "https://vega.github.io/schema/vega-lite/v4.json",
"description": "Assignment 2nd graph",
"width": 500,
"height": 500,
"padding": 5,
"data": {
"url": "https://raw.githubusercontent.com/vda-lab/vda-lab.github.io/master/assets/station_366.json"
},