knitr::opts_chunk$set( collapse = TRUE, comment = "#>" ) library(g2r)
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.
g2(diamonds, asp(carat, price, color = cut)) %>% fig_point( asp(shape = "circle", size = 3), fillOpacity = 0.3, stroke = 0 ) %>% planes(~cut+clarity, type = "rect") %>% motif(padding = c(32, 8, 48, 48))
Recreation of this example.
g2(diamonds, asp(carat, price, color = cut)) %>% fig_point( asp(shape = "circle", size = 3), fillOpacity = 0.3, stroke = 0 ) %>% planes( ~cut, type = "list", cols = 3, padding = 30 ) %>% motif(padding = c(32, 8, 48, 48))
library(dplyr) df <- diamonds %>% group_by(clarity, cut) %>% summarise( price = sum(price) ) 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
df <- data.frame( x = rep(1:50, 2), y = c(cars$speed, cars$dist), grp = rep(c("Speed", "Dist"), each = 50) ) g2(df, asp(x, y, color = grp)) %>% fig_interval() %>% planes( ~grp, padding = c(0, 48, 0, 0), type = "mirror", transpose = TRUE ) %>% motif(padding = c(32, 16, 48, 16))
g2(iris, asp(Petal.Width, Petal.Length, color = Species)) %>% fig_point() %>% planes(~Species, type = "tree")
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.