如何在R中使用ggplot绘制图形

暗中

我有包含季度和唯一客户ID列的数据框,我想要绘制一个图表,该图表将按季度来计算唯一客户。

我试过的是

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 Q3                   13210


2009 Q4                   10143
霍尔兹本

假设您的客户ID是唯一的,这可能是一个解决方案:

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

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

绘图

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

ggplot

hth

本文收集自互联网,转载请注明来源。

如有侵权,请联系 [email protected] 删除。

编辑于
0

我来说两句

0 条评论
登录 后参与评论

相关文章