How to input text in graph using R?

Description

To input the text in graph in R programming.

Title :

   Function to add labels to a plot

   R Function :title()

Text :

   To add text within graph

   R Function :text(x)

Mtext:

   To add text outside the graph.

   R Function :mtext(x)

Minor tick marks:

   To add minor tick marks both in the x and y axis

   R package :Hmisc(x)

   R Function :tick(nx=, ny=)

Legend:

   The legend is linked to the data beingm graphically displayed in the plot area of the chart.

   R Function :legend()

#Plotting
x<-mtcars$mpg
y<-mtcars$disp
plot(x,y,xlab=”mpg”,ylab=”disp”,col=”red”,col.lab=”blue”)

#Adding title
title(main=”General Plot”)

#Adding text within graph
text(x,y,row.names(mtcars),pos=4)

#Adding text outside graph
mtext(“Text Outside graph”,4)

#Adding minor tick marks
library(“Hmisc”)
minor.tick(nx=10,ny=5)

#Adding Legend
legend(“topright”,c(“One”,”Two”,”three”),fill=c(“red”,”yellow”,”green”),bg=”black”,text.col=”white”)

Leave Comment

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

clear formSubmit