2016-10-23 3 views
2

저는 초심자이고 도움이 필요합니다. gap.barplot()에서 만든 하나의 플롯에 두 번째 플롯을 추가하려하지만 실패하고 있습니다. 나는 두 벡터가 : 첫 번째 플로팅plotrix 패키지의 gap.barplot에 플롯을 추가하는 방법은 무엇입니까?

y <- as.numeric(c(92, 8, 7,6,5)) 
z <- as.numeric(c(7.5, 5.9, 5.2, 4.5, 2.3))  

확인입니다 : 내가 두 번째 플롯과 동일한 작업을 수행하기 위해 노력하고있어 후

gap.barplot(y, 
        gap = c(9, 80), 
        ytics=c(2,4,6,8,90,92), 
        col=rep("lightsalmon", 5), 
        xaxt = "n", 
        ylab = "Frequencies, n", 
        xlab = "")  

Image of the plot

그러나 떨어지게은 잘못 :

gap.barplot(z, 
     gap = c(9, 80), 
     ytics=c(2,4,6,8,90,92), 
     col=rep("green", 5), 
     xaxt = "n", 
     ylab = "Frequencies, n", 
     xlab = "", 
     main = "Colors", 
     add = T)  

이상한 반전 플롯과 오류 또는 메시지 :

Inverted plot

Error in rect(xtics[bigones] - halfwidth, botgap, xtics[bigones] + halfwidth, : 
    не могу смешивать координаты нулевой длины с ненулевыми (can not mix the coordinates of length zero with non-zero) 
In addition: Warning messages: 
1: In plot.window(...) : "add" -- не графический параметр (not graphics option) 
2: In plot.xy(xy, type, ...) : "add" -- не графический параметр (not graphics option) 
3: In title(...) : "add" -- не графический параметр (not graphics option) 
4: In axis(1, at = xtics, labels = xaxlab, ...) : 
    "add" -- не графический параметр (not graphics option) 
5: In axis(2, at = c(ytics[littletics], ytics[bigtics] - gapsize), : 
    "add" -- не графический параметр (not graphics option)  

내가 뭘 잘못입니까?

미리 감사드립니다.

답변

1

thisthis 관련 게시물이 있지만 동일한 문제가 발생했습니다. 두 번째 게시물을 기반으로 한 솔루션은 다음과 같습니다.

y <- as.numeric(c(92, 8, 7,6,5)) 
z <- as.numeric(c(7.5, 5.9, 5.2, 4.5, 2.3)) 
data=cbind(y,z); 

library(plotrix) 
barpos<-barplot(data,names.arg=colnames(data), 
       ylim=c(0,100),beside=TRUE,col=c("darkblue","red"),axes=FALSE) 
axis(2,at=c(2,4,6,8,90,92), 
    labels=c(2,4,6,8,90,92)) 
box() 
axis.break(9,80,style="gap") 

희망이 있습니다.

enter image description here

+0

감사합니다. Cristoph! 나는이 답변을 나 자신으로 발견했지만, 내가 원했던 것은 아니다 : 축에 실제 간격을 두지 않고 단지 틈새가있는 패치를 만든다. (( –

+0

@Aleks Zhang 나는 이해하지 못한다. 위의 예를 보라. – Christoph

관련 문제