
# Convert to pie (polar coordinates) and add labels

Pie = ggplot(df, aes(x="", y=share, fill=brand)) + geom_bar(stat="identity", width=1) Creating a Pie Chartįirst we'll load the ggplot2 package and create a bar chart using the geom_bar function. Next, we'll use this data frame to create the pie chart using the ggplot2 package. For this example, we'll use some sample data showing global market share for mobile phone manufacturers.ĭf = ame("brand" = c("Samsung","Huawei","Apple","Xiaomi","OPPO","Other"),

We first create a data frame containing the values that we want to display in the pie chart. Adding DataĪll you need for a pie chart is a series of data representing counts or proportions, together with the corresponding labels. In this post, we'll show how to use this package to create a basic pie chart in R.

One of the more popular packages used today is the ggplot2 package. There are various packages available for creating charts and visualizations in R. Pie charts are the classic choice for showing proportions for mutually-exclusive categories.
