Entering edit mode
6 months ago
ohtang7
▴
40
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.
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)
Thank you, I've tried but I see only some appear in the chart in wrong segments. Could you help me to solve this how ?
My code is as this.
Try following the same logic as the guide which adds the labels about halfway through each pie slice value. Check column's name in script because i don''t know you data :