参考代码如下:
library(ggplot2)
x=abs(rnorm(10))
pp=seq(0.1,1,by=0.1);pp
sx=array(0,10,1);sx
for(i in 1:10)
{
sx[i]=sum(x[1:i])
}
sx
DataCumPer=data.frame(CUM=sx,PP=pp)#一定要转换成数据框
p=ggplot(DataCumPer,aes(CUM,PP))
p=p+geom_line(linetype="dotted",size=I(0.8))#设置线型和粗细
p=p+xlab("累积和")#横轴标签
p=p+geom_point(size=I(3),shape=I(18))#设置形状和大小
p=p+ylab("百分位点")#纵轴标签
p=p+opts(axis.title.x= theme_text(size = 15,colour="red"))#设置字体和颜色
p=p+opts(axis.title.y= theme_text(size = 15,colour="blue"))#设置字体和颜色
p=p+scale_y_continuous(formatter = "percent",breaks =pp)#设置格式为百分比,10%为一档
p=p+opts(title="帕累托图",plot.title = theme_text(size = 20,face="bold",vjust=1.5))#设置图的标题
p#显示结果