Customizing the chart

Explode Pie and Donuts.

A pie and donut combo chart is made using the PieDonut() function. The aes() function is used to translate the device and browser columns to the chart’s x- and y-axes, respectively. The extent of each slice of the chart is set using the count parameter.

The degree of separation between the pie chart’s slices is determined by the explode parameter, which is set to 2, which is. Each segment is now isolated from the others in a “exploded” effect. When the explodeDonut parameter is set to TRUE.which separates the segments in the donut chart .

R




PieDonut(devices, aes(x = device, y = browser, count = share),
         explode = 2, explodeDonut = TRUE,
         ratioByGroup = FALSE)


 

Explode Pie and Donuts independently.

To explode specific slices in both the Pie and Donut charts independently, the “selected” argument is used. The values passed to “selected” are the indices of the slices to be exploded.

R




PieDonut(devices, aes(x = device, y = browser, count = share),
         explode = 2, explodeDonut = TRUE,
         selected = c(2,4,6),
         ratioByGroup = FALSE)


 

Customize start angle.

To change the starting angle of the chart, the “start” argument is used. The angle is specified in degrees.

R




PieDonut(devices, aes(x = device, y = browser, count = share),
         explode = 2, explodeDonut = TRUE,
         selected = c(2,4,6),
         start = 120,
         ratioByGroup = FALSE)


 

Add title.

To add a title to the chart, the “title” argument is used. The title is passed as a string.

R




PieDonut(devices, aes(x = device, y = browser, count = share),
         explode = 2, explodeDonut = TRUE,
         selected = c(2,4,6),
         start = 120,
         title = "Browser market share by device",
         ratioByGroup = FALSE)


 

Adjust the radius.

To adjust the radius of the chart, we can use the r0, r1, and r2 arguments of the PieDonut function.

  • r0 controls the inner radius of the chart. The default value is 0.4, which means the inner radius is 40% of the total radius.
  • r1 controls the outer radius of the chart. The default value is 0.8, which means the outer radius is 80% of the total radius.
  • r2 controls the radius of the donut hole. The default value is 0, which means there is no donut hole.
    To adjust the radius of the chart, we can change the values of r0, r1, and r2.

To adjust the radius of the chart, we can change the values of r0, r1, and r2. 

R




PieDonut(devices, aes(x = device, y = browser, count = share),
         explode = 2, explodeDonut = TRUE,
         selected = c(2,4,6),
         start = 120,
         title = "Browser market share by device",
         r0=0.3,r1=0.6,r2=0.9,
         ratioByGroup = FALSE)


 

Doughnut plot

To show donut plot without the pie chart:

R




PieDonut(devices, aes(browser, count = share),
         r0=0.6)


The devices data frame is used as the input data, and the aes function is used to map the browser variable to the x axis and the share variable to the y axis. The count argument specifies that the share variable should be used to calculate the size of each slice in the plot.

 

Donut Chart in R

Donut charts are a type of circular chart like pie charts but with hole in the middle. They’re great way for showing data in aeasy-to-see way. If you’re using R, there are loads of packages to make donut charts – think ggplot2, plotly, webr, and others. 

 Donut charts are used to show data in a circular manner . Since all of the data points are centered on the donut’s rim, it is simple to compare various data points. Additionally, since the size of the slice corresponds to the amount of the data. donut charts can be used to evaluate proportions. Donut charts are a flexible and effective method to show data in general way . 

Similar Reads

Concepts:

If we want to make a donut chart using R Programming, there are three main things we need to know. Firstly, we need the data we want to show on the chart, saved in a way that makes plotting easy like a vector or a data frame. Next, we have to select a package to make the chart with – each package’s got their own way of making and personalizing charts. And lastly, we need to figure out the various parts of the chart like the colors, labels, and slices, and how to tweak them to provide the full story we want to tell....

Steps:

Below is the basic steps outlined to create donut chart in R:...

Example 1: Simple pie and a donut graph together on one plot using ggplot2

The first thing we do is to create a sample dataset that includes the categories and values that we want to plot:...

Example 2: Pie-Donut Chart for Sample Browser Market Share using webr.

...

Customizing the chart

...

Example 3: Donut Chart using plotly package

...

Customizing the chart

...

Conclusion:

...

Contact Us