How to create a piechart using the Highcharter package in R. How to apply a theme or change the attributes. How to save the interactive chart as a static image file to be used in your documents.

Video link https://youtu.be/dvcUEqm3Wjo

# How to create a pie chart using HIGHCHARTER package in R
# How to save the interactive chart created by highcharter into a static image

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
library(highcharter)
## Registered S3 method overwritten by 'quantmod':
##   method            from
##   as.zoo.data.frame zoo
library(gapminder)

head(gapminder)
ds <- gapminder%>%
  dplyr::filter(year == max(year))%>%
  dplyr::arrange(-pop)%>%
  head(10)

hc <- ds %>%
  hchart("pie", hcaes(x = country, y = pop))%>%
    hc_title(text = "Highcharter Pie chart") %>%
      hc_subtitle(text = "Top 10 countries by population <br>techanswers88") %>%
      hc_add_theme(hc_theme_ggplot2())
    
hc
## save as a static image to be use in your word document or presentation
library(htmlwidgets)
library(webshot)
htmlwidgets::saveWidget(widget = hc, file = "D:\\tmp\\myChart.html")
webshot::webshot(url = "D:\\tmp\\myChart.html" , file ="D:\\tmp\\myPieChart.png", delay = 4 )