amPieChart: HTML widget displaying a pie chart

View source: R/amPieChart.R

amPieChartR Documentation

HTML widget displaying a pie chart

Description

Create a HTML widget displaying a pie chart.

Usage

amPieChart(
  data,
  category,
  value,
  innerRadius = 0,
  threeD = FALSE,
  depth = ifelse(variableDepth, 100, 10),
  colorStep = 3,
  variableRadius = FALSE,
  variableDepth = FALSE,
  chartTitle = NULL,
  theme = NULL,
  animated = TRUE,
  backgroundColor = NULL,
  legend = TRUE,
  caption = NULL,
  image = NULL,
  width = NULL,
  height = NULL,
  export = FALSE,
  chartId = NULL,
  elementId = NULL
)

Arguments

data

a dataframe

category

name of the column of data to be used as the category

value

name of the column of data to be used as the value

innerRadius

the inner radius of the pie chart in percent

threeD

whether to render a 3D pie chart

depth

for a 3D chart, this parameter controls the height of the slices

colorStep

the step in the color palette

variableRadius

whether to render slices with variable radius

variableDepth

for a 3D chart, whether to render slices with variable depth

chartTitle

chart title, it can be NULL or FALSE for no title, a character string, a list of settings created with amText, or a list with two fields: text, a list of settings created with amText, and align, can be "left", "right" or "center"

theme

theme, NULL or one of "dataviz", "material", "kelly", "dark", "moonrisekingdom", "frozen", "spiritedaway", "patterns", "microchart"

animated

Boolean, whether to animate the rendering of the graphic

backgroundColor

a color for the chart background; it can be given by the name of a R color, the name of a CSS color, e.g. "lime" or "olive", an HEX code like "#ff009a", a RGB code like "rgb(255,100,39)", or a HSL code like "hsl(360,11,255)"

legend

either a logical value, whether to display the legend, or a list of settings for the legend created with amLegend

caption

NULL or FALSE for no caption, a formatted text created with amText, or a list with two fields: text, a list created with amText, and align, can be "left", "right" or "center"

image

option to include an image at a corner of the chart; NULL or FALSE for no image, otherwise a named list with four possible fields: the field image (required) is a list created with amImage, the field position can be "topleft", "topright", "bottomleft" or "bottomright", the field hjust defines the horizontal adjustment, and the field vjust defines the vertical adjustment

width

the width of the chart, e.g. "600px" or "80%"; ignored if the chart is displayed in Shiny, in which case the width is given in amChart4Output

height

the height of the chart, e.g. "400px"; ignored if the chart is displayed in Shiny, in which case the height is given in amChart4Output

export

logical, whether to enable the export menu

chartId

a HTML id for the chart

elementId

a HTML id for the container of the chart; ignored if the chart is displayed in Shiny, in which case the id is given by the Shiny id

Examples

library(rAmCharts4)
dat <- data.frame(
  country = c(
    "Lithuania", "Czechia", "Ireland", "Germany", "Australia", "Austria"
  ),
  value = c(260, 230, 200, 165, 139, 128)
)
amPieChart(
  data = dat,
  category = "country",
  value = "value",
  variableRadius = TRUE
)

# shiny app demonstrating the options ####
library(rAmCharts4)
library(shiny)

dat <- data.frame(
  country = c(
    "Lithuania", "Czechia", "Ireland", "Germany", "Australia", "Austria"
  ),
  value = c(260, 230, 200, 165, 139, 128)
)

ui <- fluidPage(
  sidebarLayout(
    sidebarPanel(
      sliderInput(
        "innerRadius", "Inner radius", min = 0, max = 60, value = 0, step = 20
      ),
      checkboxInput("variableRadius", "Variable radius", TRUE),
      checkboxInput("threeD", "3D"),
      conditionalPanel(
        "input.threeD",
        checkboxInput("variableDepth", "Variable depth")
      )
    ),
    mainPanel(
      amChart4Output("piechart", height = "500px")
    )
  )
)

server <- function(input, output, session){

  piechart <- reactive({
    amPieChart(
      data = dat,
      category = "country",
      value = "value",
      innerRadius = input[["innerRadius"]],
      threeD = input[["threeD"]],
      variableDepth = input[["variableDepth"]],
      depth = ifelse(input[["variableDepth"]], 300, 10),
      variableRadius = input[["variableRadius"]],
      theme = "dark"
    )
  })

  output[["piechart"]] <- renderAmChart4({
    piechart()
  })
}

if(interactive()){
  shinyApp(ui, server)
}

rAmCharts4 documentation built on Sept. 22, 2022, 5:05 p.m.