Make a pie chart for sum of a variable

42 Views Asked by At

I am trying to make a pie chart. I am facing an issue in which the colors are filled by the group but the pie also has lines that separate each measure individually instead of by group.

This is my code:

ggplot(Book1, aes(x="", y=Eb_impact_value, fill=area))+ geom_bar(stat="identity", width=1, color="white") + coord_polar("y", start=0) + theme_void()

My data follows the following structure:

enter image description here

And this is the pie chart which results from my code:

enter image description here

1

There are 1 best solutions below

0
Ecg On

You have not given a very good reproducible example, but what I advice you to do is to first group by column 1, sum values of Column3 , then merge with the new dataframe and delete. I do not know the full name of column 3 but check the code and change it for the name:

library(dplyr)

#Assuming your df is called Book1 as in your code: 
new_df <- Book1 %>%
  group_by(Area) %>%
  summarise(Column3_Sum = sum(Column3))

final_df <- merge(Book1, new_df, by = "Area") %>%
  select(-Impact)