diamonds <- jsonlite::fromJSON(
"https://gw.alipayobjects.com/os/antvdemo/assets/data/diamond.json"
)
Recreation of this example.
g2(diamonds, asp(carat, price, color = clarity)) %>%
fig_point(
asp(shape = "circle", size = 3),
fillOpacity = 0.3, stroke = 0
) %>%
planes(~cut, type = "rect") %>%
motif(padding = c(32, 8, 48, 48))
Recreation of this example.
Recreation of this example.
library(dplyr)
#>
#> Attaching package: 'dplyr'
#> The following objects are masked from 'package:stats':
#>
#> filter, lag
#> The following objects are masked from 'package:base':
#>
#> intersect, setdiff, setequal, union
df <- diamonds %>%
group_by(clarity, cut) %>%
summarise(
price = sum(price)
)
#> `summarise()` has grouped output by 'clarity'. You can override using the `.groups` argument.
total <- df %>%
group_by(clarity) %>%
summarise(
total = sum(price)
)
df <- df %>%
left_join(total, by = "clarity") %>%
mutate(price = (price / total))
g2(df, asp(y = price, color = cut)) %>%
fig_interval(
adjust("stack"),
stroke = "#fff", lineWidth = 2
) %>%
coord_type("theta", innerRadius = .2) %>%
planes(~clarity, type = "circle") %>%
gauge_x_linear(nice = FALSE)
Recreation of this example