2013-07-02 3 views
1

안녕과 barplot를 적재 할 수 있습니다 어떻게 누적 barplot 아래 데이터 내가 ggplot2

Chr NonSyn_Snps Total_exonic_Snps 
A01 9217 13725 
A02 6226 9133 
A03 14888 21531 
A04 5272 7482 
A05 4489 6608 
A06 8298 12212 
A07 6351 9368 
A08 3737 5592 
A09 12429 18119 
A10 7165 10525 

기본적으로 내가 각 염색체에 대한 NonSyn_Snps 및 Total_exonic_Snps 스택 원하지만 불행하게도 내가 할 수없는

와 ggplot2 사용하여 만들고 싶었다.

이 내가 줄거리를 받고 있지만 하나를 적재하고 있지 않다 행운

ggplot(Chr.df_mod, aes(Chr, Total_exonic_Snps, fill = NonSyn_Snps)) + geom_bar(stat = "identity", colour = "white") + xlab("Chromosome") + ylab("Number of SNPs") 

와 함께 지금까지 시도 것입니다.

enter image description here

은 누군가가 나에게이 문제를 해결하는 데 도움이 바랍니다 수 있습니다.

감사 Upendra

답변

6

ggplot 관용구 긴 데이터가 아닌 다양한 데이터를 가장 잘 작동합니다. ggplot의 다양한 옵션을 활용하려면 광범위한 데이터 프레임을 긴 형식으로 녹여야합니다.

# get data 
dat <- read.table(text = "Chr NonSyn_Snps Total_exonic_Snps 
A01 9217 13725 
A02 6226 9133 
        A03 14888 21531 
        A04 5272 7482 
        A05 4489 6608 
        A06 8298 12212 
        A07 6351 9368 
        A08 3737 5592 
        A09 12429 18119 
        A10 7165 10525", header= TRUE) 


# load libraries 
require(ggplot2) 
require(reshape2) 

# melt data from wide to long 
dat_m <- melt(dat) 

# plot 
ggplot(dat_m, aes(Chr, value, fill = variable)) + 
    geom_bar(stat = "identity") + 
    xlab("Chromosome") + 
    ylab("Number of SNPs") 

enter image description here

+0

쿨. 팁과 대답에 감사드립니다. 매우 감사. – upendra

+0

더 많은 대화 형 플로팅을 시도하고 싶다면 (예 : 마우스 오버를 사용하여 값을 가져 오는 등) ['rCharts'] (http://ramnathv.github.io/rCharts/)에게 이동하십시오. – Ben