The Wayback Machine - https://web.archive.org/web/20240817232651/https://www.geeksforgeeks.org/how-to-plot-excel-data-in-r/
Open In App

How to plot excel data in R?

Last Updated : 26 Mar, 2021
Comments
Improve
Suggest changes
Like Article
Like
Save
Share
Report
News Follow

Plotting graph in R using an excel file, we need an excel file with two-column in it, the values in the first column will be considered as the points at the x-axis and the values in the second column will be considered as the points at the y-axis. In this article, we will be discussing the approach to plot a graph using an excel file in R language.

To import and read the excel file to the R console, the  read_excel() function from readxl library in R will be used. This function will read an excel-file available in your current working directory. To install the package of the readxl library in R the user must need to follow the following syntax in the R console.

Syntax:

install.packages(“readxl”) 

Data in use:

plot() function is used for plotting of R objects. With the provided parameters this function returns a scatter plot by default.

Syntax:

plot(x,y,main,xlab,ylab,sub,asp)

Parameters:

  • x:-the x coordinates of points in the plot
  • y:-the y coordinates of points in the plot
  • main:-an overall title for the plot
  • sub:-a subtitle for the plot
  • xlab:-a title for the x-axis
  • ylab:-a title for the y-axis
  • asp:-the y/x aspect ratio

Return:

Scatter plot of the given x and y values.

Approach

  • Import library
  • Import excel file
  • Read its data
  • Plot graph
  • Display plot

Example:

R




library(readxl)
  
Data_gfg <- read_excel("Data_gfg.xlsx")
  
plot(x = Data_gfg$x,y = Data_gfg$y,
     xlab = "x-axis",
     ylab = "y-axis",
     main = "Plot"
)


Output:



Similar Reads

Set Aspect Ratio of Scatter Plot and Bar Plot in R Programming - Using asp in plot() Function
asp is a parameter of the plot() function in R Language is used to set aspect ratio of plots (Scatterplot and Barplot). Aspect ratio is defined as proportional relationship between width and height of the plot axes. Syntax: plot(x, y, asp ) Parameters: x, y: Coordinates of x and y axis asp: Aspect ratio Example 1: # Set seed for reproducibility set
1 min read
Plot Paired dot plot and box plot on same graph in R
R Programming Language is used for statistical computing and graphics. R was first developed at the University of Auckland by two professors Ross Ihanka and Robert Gentleman Dot Plot The dot plot is a graphical representation of how one attribute varies with respect to another attribute. On the x-axis, we usually plot the attribute with respect to
7 min read
Plot Only One Variable in ggplot2 Plot in R
In this article, we will be looking at the two different methods to plot only one variable in the ggplot2 plot in the R programming language. Draw ggplot2 Plot Based On Only One Variable Using ggplot &amp; nrow Functions In this approach to drawing a ggplot2 plot based on the only one variable, firstly the user needs to install and import the ggplo
5 min read
Fit Smooth Curve to Plot of Data in R
In this article, we will learn about the concept to fit a smooth curve to the plot of data in R Programming. Smoothing is an important concept in data analysis. It is also known as curve fitting and low pass filtering. The most common non-parametric method used for smoothing is loess() function. Loess is an abbreviation for Local Regression used to
3 min read
Zoom into ggplot2 Plot without Removing Data in R
In this article, we will discuss how to zoom into the ggplot2 plot without removing data using ggplot2 package in the R programming language. The approaches to the zoom into ggplot2 plot without removing data are as follows: Zoom in to ggplot2 plot without Removing data using ylim()/xlim() functionZoom in to ggplot2 plot without Removing data using
2 min read
Rain Cloud Plots using Half Violin Plot with jittered data points in R
In this article, we will discuss how to create Rain Cloud Plots using Half Violin Plot with jittered data points in R Raincloud plots or Half Violin plots are basically used to visualize the distribution and the overall summary of the data at the same time. This plot is a combination of half violin plots with jittered points on top, boxplots and ca
2 min read
How to Plot Categorical Data in R?
In this article, we will be looking at different plots for the categorical data in the R programming language. Categorical Data is a variable that can take on one of a limited, and usually fixed, a number of possible values, assigning each individual or other unit of observation to a particular group or nominal category on the basis of some qualita
3 min read
Plotting of Data using Generic plots in R Programming - plot() Function
In this article, we will discuss how we plot data using Generic plots in R Programming Language using plot() Function. plot functionplot() function in R Programming Language is defined as a generic function for plotting. It can be used to create basic graphs of a different type. Syntax: plot(x, y, type) Parameters  x and y: coordinates of points to
4 min read
Write Data Into Excel Using R
In this article, we will discuss how to write data into excel using R Programming Language. To write data into excel, we must leverage a package called xlsx in R. The excel package is a java based language that is powerful to read, write and update data from and to excel files. Syntax: write.xlsx(data, file, sheetName, col.names, row.names, append)
2 min read
Remove Axis Values of Plot in Base R
In this article, we will be looking at the approach to remove axis values of the plot using the base functions of the R programming language. In this approach to remove the axis values of the plot, the user just need to use the base function plot() of the R programming language, and further in this function the user needs to use the axt argument of
2 min read
Add Correlation Coefficients with P-values to a Scatter Plot in R
In this article, we will discuss how to add correlation coefficients with P-value to a scatter plot in the R Programming Language. To add correlation coefficient with P-value to a scatter plot, we use the stat_cor() function of the ggpubr package in the R Language. The ggpubr package provides some easy-to-use functions for creating and customizing
2 min read
Export Plot to EPS File in R
An EPS file is a graphics file saved in the Encapsulated PostScript (EPS) file format. The EPS files may contain images, graphics, or even text. In this article, we will discuss how we export a plot to an EPS file using R programming language. Method 1 : Using setEPS() method The postscripts can be defined using the setEPS() method in R. postscript
2 min read
How to move a ggplot2 legend with multiple rows to the bottom of a plot in R
In this article, we are going to see how to draw ggplot2 legend at the bottom and with two Rows in R Programming Language. First, we have to create a simple data plot with legend. Here we will draw a Simple Scatter plot. Loading Library First, load the ggplot2 package by using library() function. library("ggplot2") Create a DataFrame for example. H
3 min read
How to Plot in 3D clusters using plotly package
R-Language is widely used in Data Science, Data Visualization Data Analysis many more, etc. Plotly package is highly rich in plotting various graphs, These graphs/charts are highly interactive and user-friendly. The 3D cluster visualizes the similarity between variables as 3-D spatial relationships. Each point in the graph represents an individual
2 min read
Control Line Color and Type in ggplot2 Plot Legend in R
In this article, we will see how to control line color and type in ggplot2 plot legend in the R programming language. Using Default Parameters In this method, inbuilt attributes are passed to the function with appropriate values to generate the requirement. Thus, in order to change the color, col or color attribute has to be passed with the column
2 min read
How to change Colors in ggplot2 Line Plot in R ?
A line graph is a chart that is used to display information in the form of series of data points. It utilizes points and lines to represent change over time. Line graphs are drawn by plotting different points on their X coordinates and Y coordinates, then by joining them together through a line from beginning to end. However, sometimes it becomes a
2 min read
How to Plot Timeseries using highcharter library in R
Time series data is a sequence of data points that are measured at regular intervals over time. Plotting time series data is a useful way to visualize trends and patterns over time. Highcharter is an R package that provides an interface to the Highcharts JavaScript charting library. Highcharts is a popular web application library for creating inter
9 min read
How to customize the axis of a Bar Plot in R
Barplots in R programming language can be created using the barplot() method. It takes as input a matrix or vector of values. The bar heights are equivalent to the values contained in the vector. Syntax: barplot(H, xlab, ylab, main, names.arg, col) Labeling the X-axis of the bar plot The names.args attribute in the barplot() method can be used to a
4 min read
Plot multiple boxplots in one graph in R
In this article, we will learn how to plot multiple boxplot in one graph in R Programming Language. This can be accomplished by using boxplot() function, and we can also pass in a list, data frame or multiple vectors to it. For this purpose, we need to put name of data into boxplot() function as input. Syntax: boxplot(x, data, notch, varwidth, name
2 min read
How to create Kernel Density Plot in R?
In this article, we will discuss how to create kernel density plots in R programming language. For this, the user simply needs to call the density() function which is an in-build function in R language. Then the user has to pass the given data as the parameter to this function in order to create a density plot of the given data and further in retur
5 min read
R plot pch symbols - Different point shapes available in R
In this article, we will discuss Pch that are built-in shapes in the R programming language. The pch (plot characters) in the R programming language are symbols or shapes we use for making plots. In the R Language, there are 26 built-in shapes that can be used in any graphic work in R Language and can be identified by numbers ranging from 0 to 25.
4 min read
How to Assign Colors to Categorical Variable in ggplot2 Plot in R ?
In this article, we will see how to assign colors to categorical Variables in the ggplot2 plot in R Programming language. Note: Here we are using a scatter plot, the same can be applied to any other graph. Dataset in use: YearPointsUsers1201130user12201220user23201315user34201435user45201550user5 To Create an R plot, we use ggplot() function and to
2 min read
Add Regression Line to ggplot2 Plot in R
Regression models a target prediction value based on independent variables. It is mostly used for finding out the relationship between variables and forecasting. Different regression models differ based on – the kind of relationship between dependent and independent variables, they are considering and the number of independent variables being used.
4 min read
Addition of more points to a Plot in R Programming - points() Function
points() function in R Language is used to add a group of points of specified shapes, size and color to an existing plot. Syntax: points(x, y, cex, pch, col) Parameters: x, y: Vector of coordinates cex: size of points pch: shape of points col: color of points Sample Scatter Plot: # R program to create a scatter plot # Creating coordinate vectors x
2 min read
Addition of Lines to a Plot in R Programming - lines() Function
lines() function in R Programming Language is used to add lines of different types, colors and width to an existing plot. Syntax: lines(x, y, col, lwd, lty) Parameters: x, y: Vector of coordinatescol: Color of linelwd: Width of linelty: Type of lineAdd of Lines to a Plot using lines() Function in RSample Scatter plot for demonstration: Here we are
3 min read
Add Color Between Two Points of Kernel Density Plot in R Programming - Using with() Function
plot() and with() functions are used to draw and add color between a particular area of two points of Kernel Density Plot in R Language. Draw a Kernel Density plot plot() function in R Language is used to draw a Kerner Density Plot Syntax: plot(dens_x) Parameters: dens_x: Default plot of density. Returns: Kernel density plot # Create example data s
1 min read
Plot Arrows Between Points in a Graph in R Programming - arrows() Function
arrows() function in R Language is used to create arrows between the points on the graph specified. Syntax: arrows(x0, y0, x1, y1, length) Parameters: x0: represents x-coordinate of point from which to draw the arrow y0: represents y-coordinate of point from which to draw the arrow x1: represents x-coordinate of point to which the arrow is drawn y1
2 min read
Plot a Geometric Distribution Graph in R Programming - dgeom() Function
dgeom() function in R Programming is used to plot a geometric distribution graph. Syntax: dgeom(x, prob) Parameters: prob: prob of the geometric distribution x: x values of the plot Example 1: # R program to illustrat # dgeom function to plot # Specify x-values for dgeom function x_dgeom &lt;- seq(2, 10, by = 1) # Apply dgeom function y_dgeom &lt;-
1 min read
Create a Plot Matrix of Scatterplots in R Programming - pairs() Function
pairs() function in R language is used to return a plot matrix, consisting of scatter plots corresponding to each data frame. R - Create Plot Matrix of Scatterplots Syntax: pairs(data) Parameters: data: It is defined as value of pairs Plot. Returns: Color, Labels, Panels, and by Group in pairs plot. Create Plot Matrix of Scatterplots in RExample 1:
2 min read
Set Axis Limits of ggplot2 Facet Plot in R - ggplot2
In this article, we will discuss how to set the axis limits of the ggplot2 facet plot in the R programming language. Method 1: Set axis limits of ggplot2 facet plot with Free Scales Here the role of the ggplot2 package is to plot the facet plot and provide some functionalities to the user, further the user needs to set the argument of the scales fu
5 min read
Article Tags :
three90RightbarBannerImg