R Programming language - R Pie Chart
www.igiitfdea.com
In R, you can create a pie chart using the pie()
function. The pie()
function takes a vector of values to plot, and several optional arguments to customize the appearance of the plot.
Here is a basic example of how to create a pie chart in R:
# Create a vector of values to plot values <- c(10, 20, 30, 40, 50) # Create a pie chart of the values pie(values)
This will create a simple pie chart with slices representing the proportion of each value in the vector.
You can customize the appearance of the pie chart by using the optional arguments of the pie()
function. For example, you can change the colors of the slices by setting the col
argument:
# Create a pie chart of the values with custom colors colors <- c("red", "green", "blue", "orange", "purple") pie(values, col = colors)
You can also add labels to the slices using the labels
argument:
# Create a pie chart of the values with labels labels <- c("A", "B", "C", "D", "E") pie(values, labels = labels)
You can control the position of the labels using the pos
argument:
# Create a pie chart of the values with labels in a different position pie(values, labels = labels, pos = 3)
You can also explode one or more slices using the explode
argument:
# Create a pie chart of the values with one slice exploded explode <- c(0, 0, 0, 0.1, 0) pie(values, explode = explode)