我正在绘制分组数据的平均值,但我无法使图例正确。文本是如此之大,以至于只能看到两组的名称,而不能看到全部四个的名称。我花了很长时间尝试使用cex-like
命令来更改大小,但是它不起作用。我曾尝试使用旋转它们las=3
,但是它不起作用。
我无法共享数据,但是代码在这里:
plot.question = function(number){
#which question to plot? get ID
question = names(sorted.by.n)[number]
#the formula
form = paste0("DF.scored.g.scale ~ ",question)
#fit it to data
fit = lm(form, DF.merged.g)
#get ANOVA results
fit.anova = anova(fit)
#get ANOVA p value
p.value = round(fit.anova[[5]][2],4) #p value
#plot it
plotmeans(as.formula(form), DF.merged.g,
ylab = "4 g-items sumscore",
xlab = "Answer",
main = paste0(questions.unique[question,"text"],"\nANOVA p=",p.value),
cex.main = .8,
cex.axis = .8,
cex.lab = .8,
cex.sub = .8,
las=3,) #size of main title
}
最好是,我想简单地缩小文本,使其适合。另外,我想旋转它以使其适合(也许与边距更改一起使用)。如果不是,还有什么?
可以使用来隐藏图例xaxt="n"
,然后必须以其他方式添加它们。可以在plotmeans()
功能内完成吗?
好吧,我尝试了很多事情,这是唯一有效的方法。显然plotmeans()创建了您无法以任何方式修改的图。我唯一能做的就是将文本作为新的纯文本图覆盖在plotmeans图的顶部。
myfactor <- factor(rep(c('cat1','cat2','cat3'),20)) #make a factor
mynum <- runif(60) #make a numeric field
plotmeans(mynum ~ myfactor,xaxt='n') #plot them
labs <- paste(names(table(myfactor)), "") #make the names
par(new=T) #create new plot
a<-rev(as.numeric(unique(myfactor))) #count the unique factors to make a vector of their numbers to serve as the positions on the x axis
text(cex=1, x=a, y=0.2, labs, xpd=TRUE, srt=35) #insert the text on the graph.
#here you need to modify y according to your data to find the best place to plot them.
#In my case x=c(1,2,3) because I have 3 categories and y=0.2
#because this is the lowest value of the y axis. The srt argument rotates the text.
您可能应该能够将y轴固定为标准值,然后在text函数的y参数中使用该数字的最小值来构成泛型函数,或者每次都计算y轴的最小值。
希望有帮助!
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句