removing x axis in error.bars

早过忘川 提交于 2019-12-22 10:57:38

问题


I've been having a problem today, I want to remove the x-axis from the following R-plot, but it just won't disappear. I want the axis to be on top. Is anybody able to help me?

library(psych)
temp <- describe(attitude)
error.bars(stats=temp,xaxt="n")
axis(3)

回答1:


You can use fixInNamespace() to edit the error.bars() function in the psych NAMESPACE. Try:

fixInNamespace(error.bars)

That will open the function in a rudimentary text editing window. Find the axis() calls and comment out the ones you don't want. Exit the editor and R will update the function in the NAMESPACE.

Then try using the function again.

Alternatively, you can print the code for error.bars() to the prompt, copy it into a text editor, change the name of the function, say to my.error.bars, and comment out the axis() calls as before. Save the function in a file and source() it into your session or copy and paste the function in. Then use to your heart's desire.

A third alternative, is to work out how error.bars() does it's base plotting - look at the code. Recreate that plot yourself, without axes, then call error.bars() with add = TRUE.




回答2:


As in the comment, you can edit the source code. Easiest way is probably to use 'fix':

eb = fix(error.bars)

should pop up an editor. Change the axis(1,.etc.) calls to axis(3,.etc.). Then you have a new function called eb() that works like error.bars.

You might want to tweak some other things too, like the title which stomps on the axes when placed at the top.




回答3:


Just to show what Gavin means with add=T :

group <- factor(rep(1:10,10))
y <- (1:10)[group] + rnorm(100)

grmean <- tapply(y,group,mean)
plot(1:10,grmean,xaxt="n",type="n")

unstacked <- unstack(data.frame(y,group),y~group)
error.bars(unstacked,add=T)
axis(3)

gives :



来源:https://stackoverflow.com/questions/5754356/removing-x-axis-in-error-bars

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!