g2_box | R Documentation |
opt param in rg2 is the PlotOptions for G2Plot.
You can construct an opt using function with g2_
prefix and g2_opt()
.
https://g2plot.antv.antgroup.com/en/api for details
g2_box(data, xField, yField, groupField = NULL, outliersField = NULL)
data |
required. Data frame for plot. |
xField |
The name of the data field corresponding to the graph in the x direction, usually the field corresponding to the horizontal coordinate axis. For example, to see how many people are in different classes, the class field is the corresponding xField. |
yField |
The name of the data field corresponding to the graph in the y direction, usually the field corresponding to the vertical coordinate axis. For example, to see the number of students in different classes, the number field is the corresponding yField. |
groupField |
grouping field |
outliersField |
outliers field |
Other g2:
g2_area()
,
g2_bar()
,
g2_bidirectional_bar()
,
g2_bullet()
,
g2_chord()
,
g2_circle_packing()
,
g2_column()
,
g2_dual_axes()
,
g2_funnel()
,
g2_gauge()
,
g2_heatmap()
,
g2_histogram()
,
g2_line()
,
g2_liquid()
,
g2_pie()
,
g2_progress()
,
g2_radar()
,
g2_radial_bar()
,
g2_ring_progress()
,
g2_rose()
,
g2_sankey()
,
g2_scatter()
,
g2_stock()
,
g2_sunburst()
,
g2_tiny_area()
,
g2_tiny_column()
,
g2_treemap()
,
g2_venn()
,
g2_violin()
,
g2_waterfall()
,
g2_word_cloud()
,
g2()
df = jsonlite::fromJSON('[
{ "x": "Oceania", "low": 1, "q1": 9, "median": 16, "q3": 22, "high": 24 },
{ "x": "East Europe", "low": 1, "q1": 5, "median": 8, "q3": 12, "high": 16 },
{ "x": "Australia", "low": 1, "q1": 8, "median": 12, "q3": 19, "high": 26 },
{ "x": "South America", "low": 2, "q1": 8, "median": 12, "q3": 21, "high": 28 },
{ "x": "North Africa", "low": 1, "q1": 8, "median": 14, "q3": 18, "high": 24 },
{ "x": "North America", "low": 3, "q1": 10, "median": 17, "q3": 28, "high": 30 },
{ "x": "West Europe", "low": 1, "q1": 7, "median": 10, "q3": 17, "high": 22 },
{ "x": "West Africa", "low": 1, "q1": 6, "median": 8, "q3": 13, "high": 16 }
]')
g2_box(df, 'x',c('low', 'q1', 'median', 'q3', 'high'))
# different data format (yField)
df = jsonlite::fromJSON('
[
{ "Species": "I. setosa", "type": "SepalLength", "value": 5.1, "bin": [4.3, 4.8, 5, 5.2, 5.8] },
{ "Species": "I. setosa", "type": "SepalWidth", "value": 3.5, "bin": [2.3, 3.2, 3.4, 3.7, 4.4] },
{ "Species": "I. setosa", "type": "PetalLength", "value": 1.4, "bin": [1, 1.4, 1.5, 1.6, 1.9] },
{ "Species": "I. setosa", "type": "PetalWidth", "value": 0.2, "bin": [0.1, 0.2, 0.2, 0.3, 0.6] },
{ "Species": "I. versicolor", "type": "SepalLength", "value": 7, "bin": [4.9, 5.6, 5.9, 6.3, 7] },
{ "Species": "I. versicolor", "type": "SepalWidth", "value": 3.2, "bin": [2, 2.5, 2.8, 3, 3.4] },
{ "Species": "I. versicolor", "type": "PetalLength", "value": 4.7, "bin": [3, 4, 4.35, 4.6, 5.1] },
{ "Species": "I. versicolor", "type": "PetalWidth", "value": 1.4, "bin": [1, 1.2, 1.3, 1.5, 1.8] },
{ "Species": "I. virginica", "type": "SepalLength", "value": 6.3, "bin": [4.9, 6.2, 6.5, 6.9, 7.9] },
{ "Species": "I. virginica", "type": "SepalWidth", "value": 3.3, "bin": [2.2, 2.8, 3, 3.2, 3.8] },
{ "Species": "I. virginica", "type": "PetalLength", "value": 6, "bin": [4.5, 5.1, 5.55, 5.9, 6.9] },
{ "Species": "I. virginica", "type": "PetalWidth", "value": 2.5, "bin": [1.4, 1.8, 2, 2.3, 2.5] }
]')
g2_box(df, 'type','bin', 'Species') |>
g2_opt(boxStyle=list(fill="#f6f"),outliersStyle=list(fill="#f6f")) |>
g2()
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.