Tutorial Gateway

  • C
  • C#
  • Python
  • SQL
  • Java
  • JS
  • BI Tools
    • Informatica
    • Talend
    • Tableau
    • Power BI
    • SSIS
    • SSRS
    • SSAS
    • MDX
    • R Tutorial
    • Alteryx
    • QlikView
  • More
    • C Programs
    • C++ Programs
    • Go Programs
    • Python Programs
    • Java Programs
  • MySQL

Stem and Leaf Plot in R

A Stem and Leaf Diagram, also called Stem and Leaf plot in R, is a special table where each numeric value split into a stem (First digit(s) ) and a leaf (last Digit). For example, 57 split into 5 as stem and 7 as a leaf. In this article, we show you how to make a Stem and Leaf plot in R Programming language with example.

Stem and Leaf Plot in R Syntax

The basic syntax to draw the Stem and Leaf chart in R Programming is as shown below

stem(x, scale = 1, width = 80, atom = 1e-08)

The following are the list of arguments supported by the Stem and Leaf chart in R programming language:

  • x: Please specify the data on which you want to draw the Stem and Leaf Plot. Here, you have to use the numeric vector, or a list containing the numeric vector.
  • scale: Please specify the scale you want to use for your plot.
  • width: It is optional, but you can use this to specify the desired width of a plot. By default, it is 80.
  • atom: It is tolerance.

Before we get into the example, let us see the diagrammatic representation of Stem and Leaf plot in R. From the below screenshot, you can see that first, we declared a variables 10, 15, 22, 25, 28, 23, 29, 31, 36, 45, 48. From those values, the First digit assigned to stem and last Digit is a leaf.

Stem and Leaf Plot in R Programming 4

Create a Stem and Leaf Plot in R Programming

In this example, we show how to make a Stem and Leaf plot in R using the ChickWeight data set, which is provided by the R Studio. If you require to import data from external files then, I suggest you to refer R Read CSV article to understand the importing of the CSV file in R Programming.

# Make a Stem and Leaf Plot in R Programming

ChickWeight

# Drawing Stem and Leaf Plot
stem(ChickWeight$weight)
Stem and Leaf Plot in R Programming 1

ChickWeight data set returns the output as a List. So, we are using the $ to extract the data from List.

stem(ChickWeight$weight)

From the above screenshot, you can see that the ChickWeight data set has numbers like 25, 29, 29, ……., 341, 361, 363.

Use Scale for Stem and Leaf Plot

In this stem and leaf plot example, we show how to use the scale argument inside the stem function.

# Make a Stem and Leaf Plot in R Programming

ChickWeight

# Drawing Stem and Leaf Plot
stem(ChickWeight$weight, scale = 2)
Stem and Leaf Plot in R Programming 2

Change width of a Stem and Leaf Plot

In this example, we change the width of a Stem and Leaf chart in R Programming.

# Make a Stem and Leaf Plot in R Programming

ChickWeight

# Drawing Stem and Leaf Plot
stem(ChickWeight$weight)
stem(ChickWeight$weight, width = 100)
stem and leaf plot in r programming 3

Filed Under: R Programming

  • R Software Download
  • Install R Packages
  • Install R Software
  • Download & Install R Studio
  • R Arithmetic Operators
  • R Comparison Operators
  • R Logical Operators
  • R If Statement
  • R If Else Statement
  • R Else If Statement
  • R Nested If Else
  • R Switch Statement
  • R Break Statement
  • R Next Statement
  • R For Loop
  • R While Loop
  • R Repeat
  • R Vector
  • R Data Frame
  • R List
  • R Arrays
  • R Matrix
  • SQL Server R Services
  • R Read CSV Function
  • R Read table Function
  • R Barplot
  • R Boxplot
  • R Histogram
  • R Pie Chart
  • R Stacked Barplot
  • R Stem and Leaf Plot
  • R Mosaic Plot
  • R ggplot2 Boxplot
  • R ggplot2 Density Plot
  • R ggplot2 Dot Plot
  • R ggplot2 Histogram
  • R ggplot2 Jitter
  • R ggplot2 Line Plot
  • R ggplot2 Scatter Plot
  • R ggplot2 Violin Plot
  • Save R ggplot using ggsave
  • R Lattice Bar chart
  • R Lattice Scatter Plot
  • R Lattice Histogram
  • R Functions
  • R Recursive Functions
  • R abs Function
  • R sqrt Function
  • R ceiling Function
  • R floor Function
  • R round Function

Copyright © 2021· All Rights Reserved by Suresh.
About | Contact | Privacy Policy