R barplot Y轴刻度太短 [英] R barplot Y-axis scale too short
问题描述
我正在尝试生成小图,但y轴比例太短.这是我的代码:
I'm trying to generate a barplot, but the y-axis scale is too short. Here's my code:
barplot(as.matrix(dat), log="y", ylim=c(10000,100000000), beside=TRUE,
ylab = "Number of reads", col = c("gray","black","white"))
它为轴留出了空间(按照ylim),但未填写实际轴.我经历过?barplot
并尝试了一些方法(从谷歌搜索中我认为xpd = F, yaxs = c(10000,10000000,5)
应该可以,但是没有用.)
It leaves the room for the axis (as per ylim), but doesn't fill in the actual axis. I've been through ?barplot
and tried a few things (from googling around I thought xpd = F, yaxs = c(10000,10000000,5)
should work, but it didn't).
我知道这是一件小事,但这确实是我多年来一直坚持的那种问题,而不是实际工作,所以任何帮助将不胜感激!
I know it's a minor thing, but it's exactly the kind of problem I get stuck on for ages, instead of actually working, so any help would be much appreciated!
为输入家伙们喝彩!
我最初的绘制没有ylim,但是最终却出现了一个更加离奇的轴(同样的问题).实际上,我选择了ylim值来给它一个更好的间隔轴.
I did initially plot without ylim, but it ends up with an even more bizarre axis (with the same problem); I actually picked my ylim values to give it a nicer spaced axis.
以下是数据:
dat <- read.table(text="D2,D3n,D3m,D4n,D4m
21234722,34262282,31920464,25486357,20712943
35343,64403,22537,39934,46547
126646,312286,101105,81537,76944", header=TRUE, sep=",")
@DWin正确-我更新了R,现在可以正常工作-谢谢大家!
Edit 2: @DWin had it right - I updated my R, and now it plots fine - thanks everyone!
推荐答案
我看到您尝试设置ylim
,但是您给出了错误的值.这将改变绘图的比例(如缩放).例如,查看此内容:
I see you try to set ylim
but you give bad values. This will change the scale of the plot (like a zoom). For example see this:
par(mfrow=c(2,1))
tN <- table(Ni <- stats::rpois(100, lambda = 5))
r <- barplot(tN, col = rainbow(20),ylim=c(0,50),main='long y-axis')
r <- barplot(tN, col = rainbow(20),main='short y axis')
另一种选择是不使用轴进行绘图,并使用axis
和usr
手动设置它们:
Another option is to plot without axes and set them manually using axis
and usr
:
require(grDevices) # for colours
par(mfrow=c(1,1))
r <- barplot(tN, col = rainbow(20),main='short y axis',ann=FALSE,axes=FALSE)
usr <- par("usr")
par(usr=c(usr[1:2], 0, 20))
axis(2,at=seq(0,20,5))
这篇关于R barplot Y轴刻度太短的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!