Warning: session_start(): open(/tmp/sess_44d6a98d31125834290970105d21ea2b, O_RDWR) failed: Disk quota exceeded (122) in /home/wvyrfnwn/learnshareit.com/wp-content/plugins/learnpress/inc/class-lp-page-controller.php on line 1007

Warning: session_start(): Failed to read session data: files (path: /tmp) in /home/wvyrfnwn/learnshareit.com/wp-content/plugins/learnpress/inc/class-lp-page-controller.php on line 1007

Warning: ftp_nlist() expects parameter 1 to be resource, null given in /home/wvyrfnwn/learnshareit.com/wp-admin/includes/class-wp-filesystem-ftpext.php on line 420

Warning: ftp_pwd() expects parameter 1 to be resource, null given in /home/wvyrfnwn/learnshareit.com/wp-admin/includes/class-wp-filesystem-ftpext.php on line 230

Warning: ftp_pwd() expects parameter 1 to be resource, null given in /home/wvyrfnwn/learnshareit.com/wp-admin/includes/class-wp-filesystem-ftpext.php on line 230

Warning: ftp_pwd() expects parameter 1 to be resource, null given in /home/wvyrfnwn/learnshareit.com/wp-admin/includes/class-wp-filesystem-ftpext.php on line 230

Warning: ftp_nlist() expects parameter 1 to be resource, null given in /home/wvyrfnwn/learnshareit.com/wp-admin/includes/class-wp-filesystem-ftpext.php on line 420

Warning: ftp_pwd() expects parameter 1 to be resource, null given in /home/wvyrfnwn/learnshareit.com/wp-admin/includes/class-wp-filesystem-ftpext.php on line 230

Warning: ftp_pwd() expects parameter 1 to be resource, null given in /home/wvyrfnwn/learnshareit.com/wp-admin/includes/class-wp-filesystem-ftpext.php on line 230

Warning: ftp_pwd() expects parameter 1 to be resource, null given in /home/wvyrfnwn/learnshareit.com/wp-admin/includes/class-wp-filesystem-ftpext.php on line 719

Warning: ftp_nlist() expects parameter 1 to be resource, null given in /home/wvyrfnwn/learnshareit.com/wp-admin/includes/class-wp-filesystem-ftpext.php on line 420

Warning: ftp_pwd() expects parameter 1 to be resource, null given in /home/wvyrfnwn/learnshareit.com/wp-admin/includes/class-wp-filesystem-ftpext.php on line 230

Warning: ftp_pwd() expects parameter 1 to be resource, null given in /home/wvyrfnwn/learnshareit.com/wp-admin/includes/class-wp-filesystem-ftpext.php on line 230

Warning: ftp_pwd() expects parameter 1 to be resource, null given in /home/wvyrfnwn/learnshareit.com/wp-admin/includes/class-wp-filesystem-ftpext.php on line 230

Warning: ftp_nlist() expects parameter 1 to be resource, null given in /home/wvyrfnwn/learnshareit.com/wp-admin/includes/class-wp-filesystem-ftpext.php on line 420

Warning: ftp_pwd() expects parameter 1 to be resource, null given in /home/wvyrfnwn/learnshareit.com/wp-admin/includes/class-wp-filesystem-ftpext.php on line 230

Warning: ftp_pwd() expects parameter 1 to be resource, null given in /home/wvyrfnwn/learnshareit.com/wp-admin/includes/class-wp-filesystem-ftpext.php on line 230

Warning: ftp_pwd() expects parameter 1 to be resource, null given in /home/wvyrfnwn/learnshareit.com/wp-admin/includes/class-wp-filesystem-ftpext.php on line 719

Warning: ftp_mkdir() expects parameter 1 to be resource, null given in /home/wvyrfnwn/learnshareit.com/wp-admin/includes/class-wp-filesystem-ftpext.php on line 562

Warning: ftp_nlist() expects parameter 1 to be resource, null given in /home/wvyrfnwn/learnshareit.com/wp-admin/includes/class-wp-filesystem-ftpext.php on line 420

Warning: ftp_pwd() expects parameter 1 to be resource, null given in /home/wvyrfnwn/learnshareit.com/wp-admin/includes/class-wp-filesystem-ftpext.php on line 230

Warning: ftp_pwd() expects parameter 1 to be resource, null given in /home/wvyrfnwn/learnshareit.com/wp-admin/includes/class-wp-filesystem-ftpext.php on line 230
text() function in R: Add the text labels to the plot - LearnShareIT

text() function in R: Add the text labels to the plot

text() function in r

In this article, we will show you how to use the text() function in R. The text() function helps you add text to a plot. Let’s follow this article to learn more about it with the explanation and examples below.

The text() Function In R

What does text() do in R?

The text() function in R can help you draw text to a plot. You can add multiple texts and you can also edit font, font-size, font-weight, color, … of a text.

With this function, you can decorate the graphs more diversely and creatively. Let’s take a look at the syntax of this function below.

Syntax:

text(latitude, longitude, labels, adj, pos , offset, vfont, cex, col, font, …)

Parameters:

  • latitude, longitude: The position (latitude, longitude) of the text will be written in the graphs.
  • labels: The character vector of the expression.
  • adj: The default is NULL. One or two values: 0,1.
  • pos: The default is NULL. The position specified for the label.
  • offset: The default is 0.5. To control the distance of the label.
  • vfont: The default is NULL. The font family of the label.
  • cex: The default is 1. The numeric character expansion factor.
  • col: The default is NULL. The color of the label.
  • font: The default is NULL. The font of the labels.

After learning the usage and the syntax of the text() function, you will learn how to use it in the next title below.

How to use the text() function?

You can use the text() function to add a label or multiple labels with the specified font, color, … to your graph.

Add text to a plot

You can add text to your plot by the text() function. 

Look at the example below.

# Create the plot
plot(1:7, xlab='Latitude', ylab ='Longitude')

# Add the content 'LearnShareIT' to a position x = 2, y = 5
text(x=2,y=5, 'LearnShareIT')

Output

Add multiple text elements to a plot

You can add multiple text elements to a plot by the text() function.

Look at the example below.

# Create the plot
plot(1:7, xlab='Latitude', ylab ='Longitude')

# Add the content 'LearnShareIT' to a position x = 2, y = 5
text(x=2,y=5, 'LearnShareIT')

# Add the content 'Author: crvt4722' to a position x = 2, y = 6
text(x=2,y=6, 'Author: crvt4722')

Output

Add the text elements to a plot with the specified color and font

You can add text elements to a plot with the specified color and font by the text() function.

Look at the example below.

# Create the plot
plot(1:7, xlab='Latitude', ylab ='Longitude')

# Add the content 'LearnShareIT' to a position x = 2, y = 5
text(x=2,y=5, 'LearnShareIT', col = "red", cex = 3)

# Add the content 'Author: crvt4722' to a position x = 2, y = 6
text(x=2,y=6, 'Author: crvt4722', col = "yellow", cex = 2)

Output

Summary

You have learned the usage, the syntax, and how to use the text() function in R. The text() function in R can help you add a text label, multiple text labels with the specified color, font, … to the plot. We hope this tutorial is helpful to you. Thanks!

Maybe you are interested:

Posted in R

Leave a Reply

Your email address will not be published. Required fields are marked *