2013-03-05 7 views
5

Ich versuche den gleichen Effekt zu erhalten, den Plot eines Barplot auf die gleiche Weise zu isolieren. R isoliert einen Boxplot mit einem Rand standardmäßig. Mit anderen Worten, ich mag die Grenze, die unten in dem ersten Plot erscheint in dem zweiten Plot erscheinen:Wie man einen Rand um ein Barplot in R zeichnet, so wie ein Rahmen für einen Boxplot gezeichnet wird

par(mfrow=c(2,1)) 

## boxplot on a formula: 
boxplot(count ~ spray, data = InsectSprays, col = "lightgray") 
# *add* notches (somewhat funny here): 
boxplot(count ~ spray, data = InsectSprays, 
     notch = TRUE, add = TRUE, col = "blue") 


require(grDevices) # for colours 
tN <- table(Ni <- stats::rpois(100, lambda=5)) 
r <- barplot(tN, col=rainbow(20)) 
#- type = "h" plotting *is* 'bar'plot 
lines(r, tN, type='h', col='red', lwd=2) 

Antwort

8

Sie haben soeben box() am Ende Ihres BarPlot Code hinzu.

par(mfrow=c(2,1)) 
boxplot(count ~ spray, data = InsectSprays, col = "lightgray") 
boxplot(count ~ spray, data = InsectSprays, 
     notch = TRUE, add = TRUE, col = "blue") 
require(grDevices) # for colours 
tN <- table(Ni <- stats::rpois(100, lambda=5)) 
r <- barplot(tN, col=rainbow(20)) 
box() 
lines(r, tN, type='h', col='red', lwd=2) 
+0

Danke! Das ist perfekt. Woher weißt du das? Finde es heraus? – Atticus29

+1

Nun, ich erinnere mich nur daran, es zu benutzen, aber nachdem ich überprüft habe, gibt der obere Link, wenn "Box rund um Barplot r hinzufügen" gegoogelt ist, die Antwort! – alexwhan

Verwandte Themen