簡體   English   中英

如何在R子圖中添加莖葉圖

[英]how to add stem-leaf plot in R subplot

我想在一個圖中包含四個子圖

其中之一是莖葉圖

我的代碼是這樣的:

attach(mtcars)
par(mfrow=c(2,2))
hist(df, main="Histogram of df",breaks=10, xlab="birth weight (oz)", col="orange")
hist(df, main="Histogram of wt",prob = TRUE,breaks=50,xlab="birth weight (oz)", col="green")
boxplot(df, main="Boxplot",col = "yellow")
stem(data)

這給了我以下錯誤

“以下對象已從包中屏蔽”

而且莖圖在我的圖中未顯示,在最后一個子圖中為空

謝謝你的幫助

您需要使用(例如) $符號定義要繪制的df變量(假設它是一個數據框)。 此外, stem給出文本作為輸出。 您必須使用text()函數將其轉換為繪圖(請參見如何將莖和葉繪圖作為繪圖輸出 )。

這是使用mtcars數據集的示例:

par(mfrow=c(2,2))
hist(mtcars$cyl, col="orange")
hist(mtcars$mpg, col="green")
boxplot(mtcars$hp, main="Boxplot",col = "yellow")
plot.new()
tmp <- capture.output(stem(mtcars$drat))
text(0, 1, paste(tmp, collapse='\n'), adj=c(0,1), family='mono', cex=1) #you can adjust the size of the text using cex parameter

在此處輸入圖片說明

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM