plotmeans传说格式

时间:2014-11-29 02:42:42

标签: r gplots

我正在绘制分组数据的方法,而且我无法让传说变得正确。文本太大,人们只能看到两个组的名称,而不是全部四个。我花了很长时间尝试使用cex-like命令来改变大小,但它没有用。我尝试使用las=3旋转它们,但它不起作用。

enter image description here

我无法共享数据,但代码在这里:

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()函数中完成吗?

1 个答案:

答案 0 :(得分:1)

我尝试了很多东西,这是唯一有用的东西。显然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.

enter image description here

您应该能够将y轴固定为具有标准值,然后在文本函数的y参数中使用该数字的最小值来生成泛型函数,或者计算每个y轴的最小值时间。

希望有所帮助!