Creation of a bubblechart object that can be inserted in a 'Microsoft' document. A bubble chart is a scatter chart where each point has a third numeric dimension controlling its size.
Arguments
- data
a data.frame
- x
column name for x values.
- y
column name for y values.
- size
column name for bubble size values (must be numeric)
- group
grouping column name used to split data into series. Optional.
- labels
column names of columns to be used as custom data labels displayed next to data points (not axis labels). Optional. If more than one name is provided, only the first one will be used as a label, but all labels (transposed if a group is used) will be available in the Excel file associated with the chart.
- asis
logical parameter defaulting to FALSE. When FALSE, the data is reshaped internally so that each series becomes a separate column. When TRUE, the data is used as-is and must already have one column for categories and one column per series, and
yaccepts a vector of series column names.asisdescribes the input shape read by the constructor. Not to be confused with thewrite_dataargument ofsheet_add_drawing.ms_chart(), which controls whethermschartwrites the chart's data into an Excel sheet at embed time. The two are independent.
See also
chart_settings(), chart_ax_x(), chart_ax_y(),
chart_data_labels(), chart_theme(), chart_labels()
Other 'Office' chart objects:
ms_areachart(),
ms_barchart(),
ms_boxplotchart(),
ms_chart_combine(),
ms_funnelchart(),
ms_histogramchart(),
ms_linechart(),
ms_paretochart(),
ms_piechart(),
ms_radarchart(),
ms_scatterchart(),
ms_stockchart(),
ms_sunburstchart(),
ms_treemapchart(),
ms_waterfallchart()
Examples
library(officer)
dat <- data.frame(
x = c(1, 2, 3, 4, 5),
y = c(10, 20, 15, 25, 30),
sz = c(5, 10, 7, 15, 12),
grp = rep("s1", 5)
)
bubble <- ms_bubblechart(
data = dat, x = "x", y = "y",
size = "sz", group = "grp"
)
# adjust axes to avoid clipping extreme bubbles
bubble <- chart_ax_x(bubble, limit_min = 0, limit_max = 6)
bubble <- chart_ax_y(bubble, limit_min = 5, limit_max = 35)
bubble
#> * 'ms_bubblechart' object
#>
#> * original data [5,4] (sample):
#> x y sz grp
#> 1 1 10 5 s1
#> 2 2 20 10 s1
#> 3 3 15 7 s1
#> 4 4 25 15 s1
#> 5 5 30 12 s1
#>
#> * series data [5,3] (sample):
#> x s1 sz-s1
#> 1 1 10 5
#> 2 2 20 10
#> 3 3 15 7
#> 4 4 25 15
#> 5 5 30 12
