Skip to content

Instantly share code, notes, and snippets.

CRIM ZN INDUS CHAS NOX RM AGE DIS RAD TAX PTRATIO B LSTAT MEDV
0.00632 18.00 2.310 0 0.5380 6.5750 65.20 4.0900 1 296.0 15.30 396.90 4.98 24.00
0.02731 0.00 7.070 0 0.4690 6.4210 78.90 4.9671 2 242.0 17.80 396.90 9.14 21.60
0.02729 0.00 7.070 0 0.4690 7.1850 61.10 4.9671 2 242.0 17.80 392.83 4.03 34.70
0.03237 0.00 2.180 0 0.4580 6.9980 45.80 6.0622 3 222.0 18.70 394.63 2.94 33.40
0.06905 0.00 2.180 0 0.4580 7.1470 54.20 6.0622 3 222.0 18.70 396.90 5.33 36.20
0.02985 0.00 2.180 0 0.4580 6.4300 58.70 6.0622 3 222.0 18.70 394.12 5.21 28.70
0.08829 12.50 7.870 0 0.5240 6.0120 66.60 5.5605 5 311.0 15.20 395.60 12.43 22.90
0.14455 12.50 7.870 0 0.5240 6.1720 96.10 5.9505 5 311.0 15.20 396.90 19.15 27.10
0.21124 12.50 7.870 0 0.5240 5.6310 100.00 6.0821 5 311.0 15.20 386.63 29.93 16.50
@hawleylin
hawleylin / vega-lite_exercise 1
Created March 25, 2020 16:13
Make a plot showing how the trip duration is related to the hour of the day. You could colour by usertype. You'll see that your plot will be compressed because of some very long durations, so only use the trips that have a duration of less than 5,000.
{
"$schema": "https://vega.github.io/schema/vega-lite/v4.json",
"description": "Assignment 1st graph",
"width": 600,
"height": "container",
"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"
},
@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_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"},
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
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
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
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
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) +