Line Chart
NC Health Insurance Coverage of Children 0-18
names <- c('Employer', 'Medicaid', 'Non-Group', 'Other Public', 'Uninsured')
series <- data.frame(
id = names, # Must be unique
name = names
)
# Note: y2 is optional - it will be displayed in parenthesis in the tooltip if specified
series$points <- list(
data.frame(
x = c('2008-01-01','2009-01-01','2010-01-01','2011-01-01','2012-01-01','2013-01-01','2014-01-01','2015-01-01','2016-01-01','2017-01-01'),
y = c(0.4843,0.4645,0.4329,0.4284,0.4208,0.4123,0.4148,0.4195,0.4243,0.4377),
y2 = c(1122700,1089000,1023300,1023700,996700,974300,983300,997500,1011000,1048000)
),
data.frame(
x = c('2008-01-01','2009-01-01','2010-01-01','2011-01-01','2012-01-01','2013-01-01','2014-01-01','2015-01-01','2016-01-01','2017-01-01'),
y = c(0.3034,0.3446,0.3793,0.3898,0.4015,0.4194,0.4237,0.4179,0.4229,0.4153),
y2 = c(703300,807900,896600,931500,950900,991100,1004200,993800,1007800,994200)
),
data.frame(
x = c('2008-01-01','2009-01-01','2010-01-01','2011-01-01','2012-01-01','2013-01-01','2014-01-01','2015-01-01','2016-01-01','2017-01-01'),
y = c(0.0665,0.0635,0.0586,0.0563,0.0585,0.0628,0.0616,0.0715,0.0639,0.0573),
y2 = c(154200,148900,138500,134600,138500,148400,146000,170000,152300,137300)
),
data.frame(
x = c('2008-01-01','2009-01-01','2010-01-01','2011-01-01','2012-01-01','2013-01-01','2014-01-01','2015-01-01','2016-01-01','2017-01-01'),
y = c(0.0397,0.0427,0.0429,0.0435,0.0434,0.0405,0.0437,0.0425,0.0427,0.0411),
y2 = c(92100,100200,101400,104000,102800,95600,103700,101100,101700,98300)
),
data.frame(
x = c('2008-01-01','2009-01-01','2010-01-01','2011-01-01','2012-01-01','2013-01-01','2014-01-01','2015-01-01','2016-01-01','2017-01-01'),
y = c(0.1060,0.0847,0.0863,0.0820,0.0757,0.0651,0.0562,0.0486,0.0463,0.0486),
y2 = c(245700,198700,204100,196000,179400,153800,133200,115600,110300,116400)
)
)
nswidgets::create_line(
series = series,
axis_labels = list(x = 'Year', y = 'Percent'),
is_time_series = TRUE,
time_format = 'YYYY', # Format Tokens: https://momentjs.com/docs/#/displaying/format/
y_format = 'percent', # 'percent', 'number', and 'none' supported
y2_format = 'none'
)
Markers
names <- c('Test 1', 'Test 2')
series <- data.frame(
id = names,
name = names
)
series$points <- list(
data.frame(
x = c(1:12),
y = c(0.1,-0.4,-0.9,-1.7,-1.2,-1.5,-1.2,-0.9,-2.1,-1.8,-1.3,-1.9)
),
data.frame(
x = c(1:12),
y = c(0.6,0.4,-0.4,-0.1,-0.6,-0.2,0.3,-0.5,-0.4,-1.1,-1.7,-1.3)
)
)
nswidgets::create_line(
series = series,
axis_labels = list(x = 'Month', y = 'Risk Difference'),
is_time_series = FALSE,
y_format = 'number', # 'percent', 'number', and 'none' supported,
markers = list(
list(label = 'Example One Label', x = '2'),
list(label = 'Example Two Label', x = '8')
),
show_horizontal_line_at_zero = TRUE
)
Relative Time
names <- c('Line 1', 'Line 2')
series <- data.frame(
id = names,
name = names
)
x <- seq(as.Date("2008-01-01"), as.Date("2010-01-01"), by="months")
series$points <- list(
data.frame(
x = x,
y = sample(60:100, length(x))
),
data.frame(
x = x,
y = sample(50:90, length(x))
)
)
nswidgets::create_line(
series = series,
axis_labels = list(x = 'Months since index', y = 'Value'),
is_time_series = TRUE,
relative_time_unit = 'months',
y_format = 'number'
)
Control Y Axis min/max
names <- c(1:2)
series <- data.frame(
id = names,
name = names
)
x <- c(1:10)
series$points <- list(
data.frame(
x = x,
y = sample(10:50, length(x))
),
data.frame(
x = x,
y = sample(40:90, length(x))
)
)
nswidgets::create_line(
series = series,
axis_labels = list(x = 'Numbers', y = 'Value'),
is_time_series = FALSE,
y_format = 'number',
y_value_domain = list(0, 100)
)
Line Colors
names <- c(1:7)
series <- data.frame(
id = names,
name = names
)
x <- c(1:10)
series$points <- list(
data.frame(
x = x,
y = sample(700000000:1000000000, length(x))
),
data.frame(
x = x,
y = sample(600000000:900000000, length(x))
),
data.frame(
x = x,
y = sample(500000000:800000000, length(x))
),
data.frame(
x = x,
y = sample(400000000:700000000, length(x))
),
data.frame(
x = x,
y = sample(300000000:600000000, length(x))
),
data.frame(
x = x,
y = sample(200000000:500000000, length(x))
),
data.frame(
x = x,
y = sample(100000000:400000000, length(x))
)
)
nswidgets::create_line(
series = series,
axis_labels = list(x = 'Numbers', y = 'Value'),
is_time_series = FALSE,
y_format = 'number'
)
Cumulative Risk
series <- data.frame(
id = c(1),
name = c('Risk')
)
risk_data = read.csv('./data/risk_curve.csv')
series$points <- list(
risk_data
)
head(risk_data, 5)
## x y yLo yHi
## 1 0.0 0.000000000 0.000000000 0.000000000
## 2 0.1 0.000000000 0.000000000 0.000000000
## 3 0.2 0.000108307 0.000000000 0.000320573
## 4 0.3 0.001231771 0.000504174 0.001959367
## 5 0.4 0.002046874 0.001101892 0.002991856
nswidgets::create_line(
series = series,
axis_labels = list(x = 'Time in months', y = 'Cumulative Risk'),
is_time_series = FALSE,
y_format = 'percent',
y_ci_format = 'percent',
curve = 'stepAfter',
show_points = F
)
Multiple Bands
series <- data.frame(
id = c(1),
name = c('Risk')
)
risk_data = read.csv('./data/risk_curve_3bands.csv')
series$points <- list(
risk_data
)
# Put these in order from widest to narrowest (bands are placed on top of each other)
series$band_names <- list(
list('wide', 'medium', 'narrow')
)
head(risk_data, 5)
## x y yLo3 yHi3 yLo2 yHi2 yLo
## 1 0.0 0.000000000 0.000000000 0.000000000 0.000000000 0.000000000 0.000000000
## 2 0.1 0.000000000 0.000000000 0.000000000 0.000000000 0.000000000 0.000000000
## 3 0.2 0.000108307 0.000000000 0.000320573 0.000000000 0.000352630 0.000000000
## 4 0.3 0.001231771 0.000504174 0.001959367 0.000453757 0.002155304 0.000378131
## 5 0.4 0.002046874 0.001101892 0.002991856 0.000991703 0.003291042 0.000826419
## yHi
## 1 0.000000000
## 2 0.000000000
## 3 0.000400716
## 4 0.002449209
## 5 0.003739820
nswidgets::create_line(
series = series,
axis_labels = list(x = 'Time in months', y = 'Cumulative Risk'),
is_time_series = FALSE,
y_format = 'percent',
y_ci_format = 'percent',
curve = 'stepAfter',
show_points = F
)
Uneven Lines
names <- c('Test 1', 'Test 2')
series <- data.frame(
id = names, # Must be unique
name = names
)
# Note: y2 is optional - it will be displayed in parenthesis in the tooltip if specified
series$points <- list(
data.frame(
x = c('2010-01-01','2011-01-01','2013-01-01','2014-01-01','2015-01-01'),
y = c(0.4329,0.4284,0.4123,0.4148,0.419),
y2 = c(1023300,1023700,974300,983300,997500)
),
data.frame(
x = c('2008-01-01','2009-01-01','2010-01-01','2011-01-01','2012-01-01','2013-01-01','2014-01-01','2015-01-01','2016-01-01','2017-01-01'),
y = c(0.3034,0.3446,0.3793,0.3898,0.4015,0.4194,0.4237,0.4179,0.4229,0.4153),
y2 = c(703300,807900,896600,931500,950900,991100,1004200,993800,1007800,994200)
)
)
nswidgets::create_line(
series = series,
axis_labels = list(x = 'Year', y = 'Percent'),
is_time_series = TRUE,
time_format = 'YYYY-MM-DD', # Format Tokens: https://momentjs.com/docs/#/displaying/format/
y_format = 'percent', # 'percent', 'number', and 'none' supported
y2_format = 'none'
)
Risk Curve Missing Point (display previous value when missing)
names <- c('Test 1', 'Test 2')
series <- data.frame(
id = names, # Must be unique
name = names
)
series$points <- list(
data.frame(
x = c(1:9),
y = c(0,0,0.01,0.02,0.03,0.05,0.08,0.13,0.21)
),
data.frame(
x = c(1,2,3,4,6,7,8,9),
y = c(0,0.019,0.029,0.039,0.089,0.139,0.219,0.349)
)
)
nswidgets::create_line(
series = series,
axis_labels = list(x = 'Time in months', y = 'Cumulative Risk'),
is_time_series = FALSE,
y_format = 'percent',
y_ci_format = 'percent',
curve = 'stepAfter',
missing_point_display = 'previous'
)