2013-08-23 47 views
-2

我有一個數據框,其中包含季度和唯一客戶ID列,我想繪製的圖形將按季度計算唯一客戶。如何在R中使用ggplot繪製圖表

是我的嘗試是

uniquegraph<-data.frame(uniqueCustomerdf) 
> uniqueCustomer<-c(uniquegraph$Customer.Id) 
> Quarter<-c(uniquegraph$Quarter) 
> uniquegraphplot<-data.frame(uniqueCustomer=uniqueCustomer,Quarter=Quarter) 
> ggplot(uniquegraphplot,aes(x=Quarter,y=uniqueCustomer)) + geom_bar(stat="identity") 

,也是我試過hist

hist(uniqueCustomer, plot=TRUE) 

但這裏如何分配季度我沒有得到

這裏是我的數據

Quarter    Customer.Id 


2009 Q1     10025 


2009 Q1     10096 


2009 Q1     10062 


2009 Q1     10030 


2009 Q1     10037 


2009 Q1     10078 


2009 Q1     10032 


2009 Q1     10243 


2009 Q1     10052 


2011 Q1     10019 


2009 Q4     13710 


2009 Q4     15310 


2009 Q4     13814 


2010 Q


2009 Q4     10143 
+2

請提供可重複的例子,或給你的數據充分說明。請參閱http://stackoverflow.com/questions/5963269/how-to-make-a-great-r-reproducible-example以獲取有關如何執行此操作的幫助。 –

+0

@RomanLuštrik我附上了數據圖片。 – snehal

+0

@ user2492230如果將數據添加爲文本(不是圖像),您將獲得更好的響應 - 請參閱[鏈接](http://stackoverflow.com/questions/5963269/how-to-make-a-great-r - 可重複的例子)羅曼建議。沒有人會手動輸入您的數據。 – zx8754

回答

0

假設你的客戶ID是唯一的,這可能是一個解決辦法:

# df--> your posted data 
# converting string to factor 
df[ ,1] <- factor(df[,1]) 

# here the standard R produce this plot: 
plot(df[,1]) 

Rplot

# if you prefer eg. ggplot 
require(ggplot2) 
qplot(df[,1]) + ylab("Frequency")+xlab("Quarters")+ geom_bar(fill="lightblue") 

ggplot

心連心

+0

@ holzbrn.Thank你。我得到了這張圖。 – snehal