Example 3: Donut Chart using plotly package
The plotly package is an R Programming package that provides an interface to create interactive web-based visualization using the Plotly JawaScript library.
R
library (plotly) # create a data frame with category labels and corresponding values data <- data.frame ( category = c ( "A" , "B" , "C" , "D" , "E" ), value = c (20, 25, 15, 10, 30) ) # define the colors for each category colors <- c ( "red" , "orange" , "yellow" , "green" , "blue" ) # set the marker properties, including the colors and line width marker <- list (colors = colors) # create the pie chart with a hole in the center plot_ly (data, labels = ~category, values = ~value, type = "pie" , hole = 0.5, marker = marker) |
First, a data frame is created with five categories labeled A through E, and their corresponding values. Then, a vector of colors is defined for each category.
Next, the marker variable is defined to include the colors for each category and any other marker properties such as line width.
Finally, the plot_ly function is used to create the pie chart, with the data data frame as the input, the category column as the labels, the value column as the values, and type = “pie” to specify that it is a pie chart. The hole parameter specifies the size of the hole in the center of the chart, and marker = marker applies the marker properties defined earlier.
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 .
Contact Us