R绘图:分段后面 - 不起作用

时间:2015-10-12 03:31:36

标签: r plot

我现在已经遇到了同样的问题一段时间了,并没有找到解决方案。 我只是想让这些片段落后于分数而不是过去。

enter image description here

我正在使用的代码:

for(i in 1:length(x)) {
plot(x[[i]],  rep(length(countries)+1-i,5) , xlim = c(0,200),ylim=c(0,length(countries)),yaxt='n', xaxt='n',ylab='',xlab = '', type='p',panel.first = c(segments(min(x[[i]]),length(countries)+1-i ,  max(x[[i]]) ,length(countries)+1-i)))
  par(new=TRUE)
  }
plot(0, xlim = c(0,200),ylim=c(0,length(countries)),yaxt='n', xaxt='n',ylab='', type='n',xlab=master$Unit[1])
par(las=2)
axis(side=2,cex.axis=.8,at=c(length(countries):1) ,labels=c(countrieslabels))
axis(side=1 ,cex.axis=.8, at=c(seq(0,max(master$DATA_VALUE+5),10))) #currently the ticks are from 0 to 150 seperated by 10
</pre></code>
I have used panel.first with success in the past to achieve something similar so I am confused as to why it is not working here. I thought it might be some little bug when using a for loop in R but then I tried the following:
<pre><code>
plot(x[[1]],  rep(length(countries)+1-1,5) ,panel.first  = c(segments(min(x[[1]]),length(countries)+1-1 ,  max(x[[1]]) ,length(countries)+1-1)), xlim = c(0,200),ylim=c(0,length(countries)),yaxt='n', xaxt='n',ylab='',xlab = '', type='p')
par(new=TRUE)
plot(0, xlim = c(0,200),ylim=c(0,length(countries)),yaxt='n', xaxt='n',ylab='', type='n',xlab=master$Unit[1])
par(las=2)
axis(side=2,cex.axis=.8,at=c(length(countries):1) ,labels=c(countrieslabels))
axis(side=1 ,cex.axis=.8, at=c(seq(0,max(master$DATA_VALUE+5),10))) #currently the ticks are from 0 to 150 seperated by 10

所以拿一个for循环的实例并没有什么区别所以我现在很难过了。我也尝试先绘制段,然后在单独的绘图中绘制点。也只是将类型更改为&#39; b&#39;对我来说不是一个选择。

1 个答案:

答案 0 :(得分:0)

默认点标记不是填充标记。这只是一个空缺的圈子。因此,绘制线和标记的顺序无关紧要。但是,如果使用填充标记,则只需要先绘制线段,然后再绘制点标记。比较每个图表,看看我的意思:

par(mfrow=c(2,2))

# Filled marker plotted after line
plot(1:10,1:10, type="l", main="Filled marker plotted after line")
points(1:10, 1:10, pch=21, col="black", bg="white")

# Filled marker plotted before line
plot(1:10,1:10, type="p", pch=21, col="black", bg="white",
     main="Filled marker plotted before line")
lines(1:10, 1:10)

# Unfilled marker plotted after line
plot(1:10,1:10, type="l", main="Unfilled marker plotted after line")
points(1:10, 1:10)

# Unfilled marker plotted before line
plot(1:10,1:10, type="p", main="Unfilled marker plotted before line")
lines(1:10, 1:10)

enter image description here