Pie chart with one column with r studio
0
0
Entering edit mode
3.6 years ago
momo.bhmd • 0

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 • 3.9k views
ADD COMMENT
1
Entering edit mode
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 REPLY
0
Entering edit mode

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

ADD REPLY
0
Entering edit mode
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 REPLY
0
Entering edit mode

Thanks a lot, it works :-)

ADD REPLY

Login before adding your answer.

Traffic: 1355 users visited in the last hour
Help About
FAQ
Access RSS
API
Stats

Use of this site constitutes acceptance of our User Agreement and Privacy Policy.

Powered by the version 2.3.6