json <- jsonlite::fromJSON(
"https://gw.alipayobjects.com/os/antvdemo/assets/data/baby-names.json"
)
json %>%
dplyr::group_by(name, year) %>%
dplyr::summarise(n = sum(n)) %>%
g2(asp(year, n, color = name, shape = "smooth")) %>%
fig_area(
adjust("stack"), adjust("symmetric"),
fillOpacity = .85
) %>%
gauge_x_linear(tickInterval = 20) %>%
legend_color(position = "right")
#> `summarise()` has grouped output by 'name'. You can override using the `.groups` argument.
df <- data.frame(
x = 1:1000,
y = rnorm(1000, mean = rep(c(25, 29, 35, 32), each = 250), 5)
)
g2(df, asp(x, y, color = y)) %>%
fig_interval(asp(size = .2)) %>%
coord_type("helix") %>%
gauge_color(c("#ffffff", "#1890FF"))
df <- data.frame(
x = c(letters[1:7], letters[1:7]),
y = round(runif(14, 20, 70)),
grp = rep(c("A", "Z"), each = 7)
)
g2(df, asp(x, y, color = grp)) %>%
fig_interval(adjust("dodge", margin = 1)) %>%
coord_type("polar") %>%
interplay("active", "region") %>%
tooltip(
showMarkers = FALSE,
shared = TRUE
)
data(diamonds, package = "ggplot2")
g2(diamonds, asp(depth, color = cut)) %>%
fig_histogram(adjust("stack"), bin_width = 1)
fruits <- data.frame(
x = c(
"Apple", "Banana", "Orange", "Coconut", "Melon",
"Grapes", "Strawberry", "Pear", "Kiwi", "Apricot"
),
y = rev(c(1, 3, 4, 6, 9, 10, 12, 13, 14, 16))
)
g2(fruits, asp(x, y)) %>%
fig_interval(asp(shape = "line")) %>%
fig_point(asp(shape = "circle")) %>%
coord_type("theta", innerRadius = .2, endAngle = pi) %>%
axis_x(
tickLine = NULL,
grid = NULL,
line = NULL,
label = list(offset = 20)
) %>%
info_text(
position = c("50%", "50%"),
content = "Fruits",
style = list(
textAlign = "center",
fontSize = 30
)
)
df <- data.frame(
x = c(1:50, 1:50),
y = rnorm(100, rep(c(10, 5), each = 50)),
grp = rep(c("Male", "Female"), each = 50)
)
g2(df, asp(x, y, color = grp)) %>%
fig_interval() %>%
planes(~grp, type = "mirror") %>%
gauge_color(c("#8adb9a", "#ffa6a6")) %>%
interplay("element", "highlight")
df <- data.frame(
x = head(fruits$x, 7),
y = rnorm(7, 10, 3)
)
g2(df, asp(x, y, color = x)) %>%
fig_interval(
lineWidth = 1, stroke = "#fff"
) %>%
coord_type("polar", innerRadius = .2) %>%
axis_hide() %>%
interplay("element", "highlight") %>%
legend_color(position = "right") %>%
tooltip(showMarkers = FALSE)
g2(fruits, asp(x, y, color = y)) %>%
fig_interval(
asp(label = y),
lineWidth = 1,
stroke = "#fff"
) %>%
coord_type(
"polar",
startAngle = pi,
endAngle = pi * (3 / 2)
) %>%
gauge_color(c("rgb(255,215,135)", "rgb(252,143,72)")) %>%
gauge_y_linear(tickCount = 10) %>%
interplay("element", "highlight") %>%
gauge_label(offset = -15) %>%
axis_x(
tickLine = list(aligntick = FALSE),
grid = list(alignTick = FALSE)
) %>%
axis_y(
grid = list(closed = FALSE)
) %>%
tooltip(showMarker = FALSE)
diamonds_small <- jsonlite::fromJSON(
"https://gw.alipayobjects.com/os/antvdemo/assets/data/diamond.json"
)
diamonds_small$type <- "1"
g2(diamonds_small, asp(clarity, type, color = clarity)) %>%
fig_point(
asp(shape = "circle"),
adjust("jitter"),
fillOpacity = .4
) %>%
coord_type("polar") %>%
legend_color(FALSE) %>%
gauge_y_cat(range = c(0, 1))
fruits2 <- fruits
fruits2$y <- rev(fruits2$y)
g2(fruits2, asp(x, y, color = y)) %>%
fig_interval() %>%
coord_type("polar", innerRadius = .2) %>%
coord_transpose() %>%
gauge_color(c("#BAE7FF", "#1890FF", "#0050B3")) %>%
gauge_y_linear(max = 20) %>%
axis_x(
tickLine = NULL,
grid = NULL,
line = NULL,
label = list(offset = 20)
) %>%
legend_color(FALSE)
df <- data.frame(x = 1:10, y = round(rnorm(10, sd = 5)))
cb <- htmlwidgets::JS(
"(value) => {
if(value > 0)
return '#8adb9a';
return '#ffa6a6';
}"
)
g2(df, asp(x, y, color = y)) %>%
fig_interval(asp(label = y)) %>%
gauge_color(cb) %>%
legend_color(FALSE)
df <- data.frame(
x = c(LETTERS[1:8], LETTERS[1:8]),
y = runif(16, 10, 15),
grp = rep(c("Grp A", "Grp B"), each = 8)
)
g2(df, asp(x, y, color = grp)) %>%
fig_area() %>%
fig_line(asp(size = 2)) %>%
fig_point(asp(size = 4, shape = "circle")) %>%
coord_type("polar", radius = .8) %>%
tooltip(
shared = TRUE,
showCrosshairs = TRUE,
crosshairs = list(
line = list(
style = list(
lineDash = c(4, 4),
stroke = "#333"
)
)
)
)
traffic <- data.frame(
label = c("Visit", "Portal", "Signup", "Pay", "Retain"),
users = c(1, .7, .5, .3, .1)
)
cb <- htmlwidgets::JS(
"(label, users) => {
return {
content: `${label} ${users * 100}%`,
};
}"
)
g2(traffic, asp(label, users, color = label), reorder = FALSE) %>%
fig_interval(
asp(shape = "funnel", label = label, label = users),
adjust("symmetric")
) %>%
gauge_color(c('#0050B3', '#1890FF', '#40A9FF', '#69C0FF', '#BAE7FF')) %>%
coord_transpose() %>%
coord_scale(1, -1) %>%
axis_hide() %>%
gauge_label(cb)
weekday <- c("Mon", "Tue", "Wed", "Thu", "Fri", "Sat", "Sun")
employee <- LETTERS[1:10]
roster <- expand.grid(weekday = weekday, employee = employee)
roster$sales <- round(runif(nrow(roster), 10, 50))
g2(roster, asp(employee, weekday, color = sales)) %>%
fig_polygon(
asp(label = sales),
lineWidth = 1,
stroke = "#fff"
) %>%
gauge_color(c("#BAE7FF", "#1890FF", "#0050B3"))
g2(roster, asp(employee, weekday, color = sales)) %>%
fig_polygon(
asp(label = sales),
lineWidth = 1,
stroke = "#fff"
) %>%
gauge_color(c("#BAE7FF", "#1890FF", "#0050B3")) %>%
coord_type("polar", innerRadius = .2) %>%
axis_y(
grid = NULL,
line = NULL,
tickLine = NULL,
label = NULL
) %>%
axis_x(
grid = NULL,
line = NULL,
tickLine = NULL
)
df <- data.frame(
grp = rep(c("FR", "US", "SA", "CN", "BE"), each = 50),
values = rnorm(
250,
rep(c(47, 37, 35, 42, 39), each = 50),
rep(c(1, 2, 3, 3, 2), each = 50)
)
)
g2(df, asp(grp, values, color = grp)) %>%
fig_boxplot(asp(size = 60)) %>%
coord_type("polar", innerRadius = .2) %>%
legend_color(position = "top")
df <- data.frame(
x = letters,
y = runif(26)
)
df$max <- 1
g2(df, asp(x, y), elementId = "x") %>%
fig_interval(asp(y = max), fill = "lightgrey") %>%
fig_interval(asp(, size = 8)) %>%
gauge_y_linear(min = 0, max = 1)