2013-03-05 199 views
5

我試圖以同樣的方式獲得隔離barplot的陰謀的相同效果R用邊框分隔boxplot默認。換句話說,我希望下面出現在第一條曲線的邊界出現在第二個情節:如何在R中圍繞barplot繪製邊框與爲boxplot繪製邊框的方法相同

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) 

回答

8

你只是在你的代碼barplot末尾添加box()

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

謝謝!那很完美。你是怎麼知道這些/瞭解它的? – Atticus29 2013-03-06 00:19:43

+1

嗯,我只記得它使用它,但剛剛檢查時,「添加框附近barplot r」的頂部鏈接是谷歌搜索給出了答案! – alexwhan 2013-03-06 11:16:30