我目前正在使用以下方法绘制ROAS密度图,按生成ROAS的年份分组(campaign.year)
densityplot(~roas,data=ndb.data.analysis,groups=campaign.year,plot.points=FALSE,auto.key = list(columns=4),main="Distribution of ROAS by Year",from=0,xlab="Return on Ad Spend ($)",ylab="Percent of Observations")我想在关键字中指出每一年的观察次数。
有没有一个好的(简单的)方法来做到这一点?
谢谢!
发布于 2016-05-19 00:12:05
您不提供数据,所以使用内置数据集。使用key参数,您可以自定义图例。
library(lattice)
data(mtcars)
# number observations for each cylinder count
nobs = aggregate(mtcars$mpg,list(mtcars$cyl),length)
nobs # see results
# construct labels to include nobs
labels=paste0(levels(as.factor(mtcars$cyl))," (",nobs$x," obs.)")
linecolor = trellis.par.get("superpose.symbol")$col[1:length(labels)]
densityplot(~mpg,mtcars,groups=cyl,lwd=2,
key=list(space="right",adj=0,title="No. cylinders",
lines=list(pch=1,col=linecolor,lwd=2),
text=list(labels))
)https://stackoverflow.com/questions/37278544
复制相似问题