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

如何在R中使用ggplot绘制图形,r,ggplot2,R,Ggplot2,我有一个包含季度和唯一客户ID列的数据框,我想要的是绘制一个图表,按季度统计唯一客户 我试过的是 uniquegraph<-data.frame(uniqueCustomerdf) > uniqueCustomer<-c(uniquegraph$Customer.Id) > Quarter<-c(uniquegraph$Quarter) > uniquegraphplot<-data.frame(uniqueCustomer=uniqueCustomer

我有一个包含季度和唯一客户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")
但这里如何分配我没有得到的四分之一

这是我的数据

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


hth

请提供一个可复制的示例或对您的数据进行充分说明。请参阅以获取有关如何执行此操作的帮助。@Roman Luštrik我已附加了数据图像。@user2492230如果将数据添加为文本(而不是图像),您将获得更好的响应-请参阅Roman建议的。没有人会手工输入您的数据。对不起。现在我编辑了我的图像进行测试。请参阅我提供的链接,特别是关于
dput
@holzbrn的部分。谢谢。我拿到了图表。
# 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")