0

I want to have four subplot in one figure

one of them is a stem-leaf plot

My code like this :

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)

And this gives me the following error

"The following object is masked from package"

and the stem plot does not show in my figure it is empty in the last subplot

THANKS for your help

Eleven11
  • 3
  • 1
  • You may want to have a look at https://stackoverflow.com/questions/26532564/how-to-output-a-stem-and-leaf-plot-as-a-plot – DJack Mar 01 '18 at 14:33

1 Answers1

0

You need to define the variables of df (assuming it is a data frame) you want to plot using (for instance) the $ sign. Furthermore, stem gives a text as output. You have to convert it to a plot using text() function (see How to output a stem and leaf plot as a plot).

Here is an example using mtcars dataset:

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

enter image description here

DJack
  • 4,850
  • 3
  • 21
  • 45