I made this .csv file called pie_chart.csv. I've been trying to make a pie chart for every single sample that is on there, with the other columns being categories that the pie charts display. I currently have this so far:
#Pie Chart
library(readr)
x <- read_csv("pie_chart.csv")
#rename the first column
colnames(x)[colnames(x)=="X1"] <- "Sample"
I am confused as to how to continue from here. I have tried a for loop but would appreciate any help that is given! Thank you!
I transposed the data and tried using a for loop. In another data set this worked, however, for this data it is giving me errors:
x <- t(x)
names2 <- colnames(x[,2])[colnames(x) != "Sample"]
for (i in 2:col) {
mypath2 <- file.path("C:","Users", "Prak Lab", "Desktop","REPORTS", "text files",
paste(names2[i],"pie", ".jpg", sep = ""))
jpeg(file = mypath2)
pie(table(x[,i]), labels = x[,1], col = c("darkred","pink"), main = colnames(x[i]))
#title = colnames(x[i])
dev.off()
}
This is head(x):
Sample Reads_used_in_Clonotypes Unsuccessful_Reads Not_used_for_Clonotypes
1 012-915-8-rep1 0.772 0.1540 0.0743
2 012-915-8-rep2 0.888 0.0436 0.0681
3 012-915-8-rep3 0.856 0.0470 0.0966
4 012-915-8-rep4 0.873 0.0525 0.0741
5 012-915-8-rep5 0.860 0.0440 0.0962
6 012-915-8-rep6 0.905 0.0286 0.0667