This is a test version of Biostars. For the public version, visit https://www.biostars.org.
Pie chart with one column with r studio

Hi, im new in r studio. I want to create pie chart on one specific column in my data frame (2140 observation) that indicates the percentage of each transcript category (tx_type). I want to inform you that the type of tx_type is "character" (e.g protein_coding, processed_pseudogene, nonsense_mediated_decay ...).I tried the following code and I obtained the adjoint image https://ibb.co/TqsNTPN

p=ggplot(sk_vf1,aes(x="",fill=tx_type)) + geom_bar(width=1) +coord_polar(theta="y") + scale_fill_manual(values = colorRampPalette(brewer.pal(12, "Set3"))(nb.cols)) p + theme_void()

"sk_vf1" is the name of my data frame

I wanted to have a pie chart that indicate the occurence percentage of each transcript category (tx_type). Therefore, I tried the following code j=paste(prop.table(table(sk_vf1$tx_type))*100, "%", sep = "") p=ggplot(sk_vf1,aes(x="",fill=tx_type)) + geom_bar(width=1) +coord_polar(theta="y") + geom_label(aes(label =j)) p + scale_fill_manual(values = colorRampPalette(brewer.pal(12, "Set3"))(nb.cols))

Unfortunately, I get the following error: Aesthetics must be either length 1 or the same as the data (2140): label

Thanks in advance, any little help will be appreciated :-)

pie chart rna-seq r
library(ggplot2)
ggplot(iris, aes(x="", y=Sepal.Width, fill=Species)) +
    geom_bar(stat="identity", width=1) +
    coord_polar("y", start=0)+
    scale_fill_brewer(palette="Dark2")

Rplot

Thanks for your reply, I already performed the pie chart (check the link below), I want to add the percentage

library(dplyr)
library(ggplot2)
iris %>% 
    group_by(Species) %>% 
    summarise(sep_sum=sum(Sepal.Length))%>%
    mutate(perc=sep_sum/sum(sep_sum)*100) %>%
    ggplot(aes(x="", y=sep_sum, fill=Species))+
    geom_bar(stat="identity", width=1) +
    theme(legend.position = "None",
          axis.title = element_blank(),
          axis.ticks = element_blank()) +
    geom_text(aes(label = paste0(Species,"\n",round(perc,2),"%")), position = position_stack(vjust = 0.5), size=6) +
    coord_polar("y", start=0)

Rplot

note: Please prefer other quantitative visualizations for scientific data.

0 answers

No answers yet.

Log in to answer this question.