Customizing the chart
Add title to the chart.
R
plot_ly (data, labels = ~category, values = ~value, type = "pie" , hole = 0.5, marker = marker)%>% # customize the layout of the chart, including the title and legend layout (title = "Donut Chart Example" ) |
The layout function is used to add a title to the chart, with the text “Donut Chart Example”. This improves the chart by adding context and clarity to what the chart is showing.
Add a label and text info
R
# define the text and hover information to be displayed on the chart textinfo <- "label+percent" hoverinfo <- "text" ... # create the pie chart with a hole in the center plot_ly (data, labels = ~category, values = ~value, type = "pie" , hole = 0.5, marker = marker, text = ~ paste (category, value, sep = ": " ), textinfo = textinfo, hoverinfo = hoverinfo) |
...
To improve the chart by providing more information and context for the data presented and making it easier for the viewer to interpret and understand the chart. The text parameter is added to display the label and value of each category on the chart, separated by a colon (:). The textinfo parameter is also defined as “label+percent” to show both the label and the percentage of each category in the chart.
Additionally, the hoverinfo parameter is set to “text” to display the text defined in text when the user hovers over each category in the chart.
Donut chart thickness
R
plot_ly (data, labels = ~category, values = ~value, type = "pie" , hole = 0.8, marker = marker)%>% # customize the layout of the chart, including the title and legend layout (title = "Donut Chart Example" ) |
We can maintain the thickness of donut chart by increase or decrease the value in hole.
Adding Custom color Palettes
R
# define the colors for each category colors <- c ( "#2ecc71" , "#3498db" , "#f1c40f" , "#e74c3c" , "#9b59b6" ) # set the marker properties, including the colors and line width marker <- list (colors = colors) |
The colors of the pie chart are changed to a custom color palette. Specifically, the hex codes for five colors (green, blue, yellow, red, and purple) are defined and stored in the colors vector. These colors are then passed to the marker parameter to set the colors for each category in the pie chart.
This change improves the chart by using a custom color scheme that is more visually appealing and/or aligned with a particular branding or design style.
Customizing legend
R
colors <- c ( "#2ecc71" , "#3498db" , "#f1c40f" , "#e74c3c" , "#9b59b6" ) # set the marker properties, including the colors and line width marker <- list (colors = colors) # define the text and hover information to be displayed on the chart textinfo <- "label+percent" hoverinfo <- "text" # create the pie chart with a hole in the center chart <- plot_ly (data, labels = ~category, values = ~value, type = "pie" , hole = 0.5, marker = marker, text = ~ paste (category, value, sep = ": " ), textinfo = textinfo, hoverinfo = hoverinfo) # customize the layout of the chart, including the title and legend layout (chart, title = "Donut Chart Example" , legend = list (x = 0, y = 1, font = list (size = 14, color = "black" ))) |
Added a legend customization to the plot using the layout function. The purpose of this change is to adjust the position and font of the legend to make it more readable and aesthetically pleasing.
Adding a Pie Slice Border
R
chart <- plot_ly (data, labels = ~category, values = ~value, type = "pie" , hole = 0.5, marker = marker, text = ~ paste (category, value, sep = ": " ), textinfo = textinfo, hoverinfo = hoverinfo) # customize the layout of the chart, including the title and legend layout (chart, title = "Donut Chart Example" , legend = list (x = 0, y = 1, font = list (width = 2, color = "blue" ))) |
Added the “line” parameter to the “marker” list with values specifying the color and width of the marker line. This adds a line border around each pie slice.
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