2016-10-23 4 views
2

Ich bin der R Anfänger und ich brauche Hilfe. Ich versuche, einen zweiten Plot zu einem in gap.barplot() erstellten Plot hinzuzufügen, aber fehlgeschlagen. Ich habe zwei Vektoren:Wie fügt man plot zu gap.barplot im plotrix-Paket hinzu?

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

die erste Plotten ist ok:

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

Aber nachdem ich versuche, das gleiche mit dem zweiten Grundstück zu tun, smth schief geht :

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)  

Ich sehe seltsame invertierte Handlung und die err oder Nachricht:

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)  

Was mache ich falsch?

Vielen Dank im Voraus!

Antwort

1

Ich fand this und this verwandte Beiträge, aber lief in den gleichen Schwierigkeiten. Hier ist eine Lösung basierend auf dem zweiten Beitrag:

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") 

Ich hoffe, dass das hilft.

enter image description here

+0

Danke, Cristoph! Ich habe diese Antwort selbst gefunden, aber das ist nicht das, was ich wollte: Es macht nicht wirklich Lücke in der Achse, macht nur eine Lücke aussehende Patch auf. (( –

+0

@Aleks Zhang ich verstehe nicht. Siehe mein Beispiel oben. Was erwarten Sie dann? – Christoph

Verwandte Themen