【问题标题】:how to add stem-leaf plot in R subplot如何在 R 子图中添加茎叶图
【发布时间】:2018-03-01 14:26:27
【问题描述】:

我想在一个图中有四个子图

其中一个是茎叶图

我的代码是这样的:

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)

这给了我以下错误

“以下对象已从包中屏蔽”

在我的图中没有显示主图,在最后一个子图中它是空的

感谢您的帮助

【问题讨论】:

标签: r plot


【解决方案1】:

您需要使用(例如)$ 符号定义要绘制的 df 的变量(假设它是一个数据框)。此外,stem 给出一个文本作为输出。您必须使用text() 函数将其转换为绘图(请参阅How to output a stem and leaf plot as a plot)。

这是一个使用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

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2020-06-16
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多