Pie chart in R revising to match the segment

Hello,

I am just curious if there is any function in R that I can use to create the pie chart graph shown in the figure?

I want to draw lines that connect the assigned labels to each segment of the pie chart, similar to what is depicted in the figure.

Could you please let me know if there is a package or another method to achieve this in R?

Thanks.![enter image description here][1]

FYI my code is as

library(ggplot2)
library(readxl)
data2 <- read_excel("Pigeon_RelativeAbundance.xlsx", sheet = "Sheet1")

genus_colors <- c("#FF0000", "#FF7F00", "#FFFF00", "#00FF00", "#00FFFF", "#0000FF", "#8B00FF", "#FF00FF",
"#FF4500", "#FF8C00", "#FFD700", "#ADFF2F", "#00FF7F", "#40E0D0", "#00BFFF", "#8A2BE2",
"#9932CC", "#FF1493", "#FF69B4", "#FFC0CB", "#FFE4B5", "#008888", "#0CCCCC", "#009900",
"#FAFAD2")

Create pie chart

plot_a <- ggplot(data2, aes(x = "", y = RelativeAbundance, fill = Taxa)) +
geom_bar(width = 1, stat = "identity") +
coord_polar(theta = "y") + # Convert to polar coordinate system
scale_fill_manual(values = genus_colors) +
theme_void() + # Remove background and gridlines
theme(legend.position = "bottom") + # Move legend to bottom
guides(fill = guide_legend(title = "Taxa")) + # Customize legend title
labs(title = "A") # Add title

print(plot_a)

1 Like

Hi @SingeunOh,
I would look at this gallery of pie charts from R, it might have some insight for you!

1 Like

I have tried to use geom_label_repel function. However, it seems the lable appears in wrong positions.

How Can I modify my code ? I guess it would be better each lable should be connected to out of the chart through line.

plot_a <- ggplot(data, aes(x = "", y = Proportion, fill = Taxa)) +
geom_bar(width = 1, stat = "identity") +
coord_polar(theta = "y") + # Convert to polar coordinate system
scale_fill_manual(values = genus_colors) +
theme_void() + # Remove background and gridlines
theme(legend.position = "bottom") + # Move legend to bottom
guides(fill = guide_legend(title = "Taxa")) + # Customize legend title
labs(title = "A") + # Add title
geom_label_repel(aes(label = Taxa),
show.legend = FALSE,
box.padding = 0.001,
point.padding = 0.001,
point.size = 1,
min.segment.length = 0.001,
angle = 45)

Hello @SingeunOh,

Troubleshooting people's code is generally outside of the scope of what we do on the forum. There are many, many other resources for getting help with ggplot visualizations.