Question: Pie chart with one column with r studio
0
gravatar for momo.bhmd
4 months ago by
momo.bhmd0
momo.bhmd0 wrote:

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 :-)

R rna-seq pie chart • 360 views
ADD COMMENTlink modified 4 months ago • written 4 months ago by momo.bhmd0
1
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

ADD REPLYlink written 4 months ago by cpad011215k

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

ADD REPLYlink written 4 months ago by momo.bhmd0
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.

ADD REPLYlink modified 4 months ago • written 4 months ago by cpad011215k

Thanks a lot, it works :-)

ADD REPLYlink written 4 months ago by momo.bhmd0
Please log in to add an answer.

Help
Access

Use of this site constitutes acceptance of our User Agreement and Privacy Policy.
Powered by Biostar version 2.3.0
Traffic: 1338 users visited in the last hour
_