The Wayback Machine - https://web.archive.org/web/20240927174930/https://www.geeksforgeeks.org/plotting-graphs-using-two-dimensional-list-in-r-programming/
Open In App

Plotting Graphs using Two Dimensional List in R Programming

Last Updated : 01 Jun, 2020
Summarize
Comments
Improve
Suggest changes
Like Article
Like
Save
Share
Report
News Follow

List is a type of an object in R programming. Lists can contain heterogeneous elements like strings, numeric, matrices, or even lists. A list is a generic vector containing other objects. Two-dimensional list can be created in R programming by creating more lists in a list or simply, we can say nested lists. The list() function in R programming is used to create a list. In this article, we’ll learn to create plot graph using Two Dimensional List in R programming.

Creating a Two Dimensional list

A Two Dimensional list can be created with the use of list() function.

Syntax: list(x)

Parameter:
x: represents objects to be inserted in list

Example:




# Defining objects
x <- c(1, 2, 3, 4)
  
y <- LETTERS[1:4]
  
# Adding lists into a list
ls <- list(
  list(x), 
  list(y)
)
  
# Print list
print(ls)


Output:

[[1]]
[[1]][[1]]
[1] 1 2 3 4


[[2]]
[[2]][[1]]
[1] "A" "B" "C" "D"

Creating Plot Graph using Two Dimensional List

To create plot graphs, lists have to be passed as vectors to the plot() function as coordinate values. The unlist() function converts the list into an atomic type of vector.

Example:




# Creating nested lists with random values
ls <- list(
  list(rnorm(20, mean = 10, sd = 2)),
  list(rnorm(20, mean = 100, sd = 10)))
  
# Output to be present as PNG file
png(file = "2DListGraph.png")
  
# Plotting list
plot(unlist(ls[[1]]), unlist(ls[[2]]))
  
# Saving the file
dev.off()


Output:



Similar Reads

Two Dimensional List in R Programming
A list in R is basically an R object that contains within it, elements belonging to different data types, which may be numbers strings or even other lists. Basically, a list can contain other objects which may be of varying lengths. The list is defined using the list() function in R. A two-dimensional list can be considered as a "list of lists". A
5 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
Graph Plotting in R Programming
When it comes to interpreting the world and the enormous amount of data it is producing on a daily basis, Data Visualization becomes the most desirable way. Rather than screening huge Excel sheets, it is always better to visualize that data through charts and graphs, to gain meaningful insights. R - Graph Plotting The R Programming Language provide
5 min read
Plotting ROC curve in R Programming
Error metrics allow us to evaluate and justify the model's performance on a specific dataset. One such error metric is the ROC plot. A classification error metric is the ROC plot, also known as the ROC AUC curve. That is, it assesses the performance and outcomes of classification machine learning algorithms. To be more specific, the ROC curve repre
4 min read
Create One Dimensional Scatterplots in R Programming - stripchart() Function
Strip Chart is defined as one dimensional scatter plots or dot plots which is used as an alternative to box plot when sample sizes are small. It is created using the stripchart() function in R Language. R - stripchart Function Syntax: stripchart(x, data = NULL method, jitter ) Parameters: x : value of data from which the plots are to be produced.da
3 min read
Plotting multiple time series on the same plot using ggplot in R
Time series data is hierarchical data. It is a series of data associated with a timestamp. An example of a time series is gold prices over a period or temperature range or precipitation during yearly storms. To visualize this data, R provides a handy library called ggplot. Using ggplot, we can see all sorts of plots. Along with ggplot, R also provi
3 min read
Adding table within the plotting region of a ggplot in R
In this article, we are going to see how to add the data frame table in the region of the plot using ggplot2 library in R programming language. Dataset in use: Here we are plotting a scatterplot, the same can be done for any other plot. To plot a scatter plot in ggplot2, we use the function geom_point( ). Syntax: geom_point(mapping=NULL, data=NULL,
2 min read
Plotting time-series with Date labels on X-axis in R
In this article, we will discuss how to plot time-series with date labels on the x-axis in R Programming Language supportive examples. Method 1 : Using plot() method The plot() method in base R is a generic plotting function. It plots the corresponding coordinates of the x and y axes respectively. The plot can be customized to add the line type, li
2 min read
R - How to plotting log-scaled histograms in plotly
A histogram is a graph that displays the frequency or number of occurrences of different values or ranges of values in a dataset. The x-axis represents the values in the dataset and the y-axis represents the frequency of those values. The range of values is divided into bins, and the height of each bar in the histogram represents the frequency of v
5 min read
How to Debug Error in plot.new() - R Plotting Issues
Plotting in R is an effective tool for visualizing data, but errors are not uncommon, especially when dealing with complex plots or huge datasets. This issue usually arises when you try to add additional plots to an existing plot region or create a new plot without clearing the previous one. In this article, we'll explore some common errors when us
3 min read
R - Charts and Graphs
R language is mostly used for statistics and data analytics purposes to represent the data graphically in the software. To represent those data graphically, charts and graphs are used in R. R - graphs There are hundreds of charts and graphs present in R. For example, bar plot, box plot, mosaic plot, dot chart, coplot, histogram, pie chart, scatter
6 min read
Draw Multiple Graphs and Lines in Same Plot in R
A visualization can sometimes make more sense when multiple graphs and line plots are combined into one plot. In this article, we will discuss how we can do the same in the R programming language. Method 1: Using base R Base R supports certain methods that can be used to generate the desired plot. In this example plot, a scatter plot, a line plot,
3 min read
Create interactive ggplot2 graphs with Plotly in R
"A Picture is worth a thousand words," and that picture would be even more expressive if the user could interact with it. Hence the concept of "interactive graphs or charts. Interactive charts allow both the presenter and the audience more freedom since they allow users to zoom in and out, hover and read information related to the marker, get toolt
6 min read
How To Put Multiple Graphs In One Plot With Ggvis in R
In this article, we will be looking at the approach to putting multiple graphs in one plot using ggvis in the R programming language. The ggplot2 library in R is used to make a graphical representation of the data provided. The package can be downloaded and installed into the working space using the following command : install.packages("ggplot2") A
3 min read
How to personalize easily ggplot2 graphs in R
In this article, we are going to learn how to personalize easily ggplot2 graphs in the R programming language. Data visualization is an essential tool for understanding and communicating complex data sets. One of the most popular and powerful visualization libraries in R is ggplot2, which offers a wide range of options for creating visually appeali
11 min read
Grouped Bar Graphs and Facet_Wrap in R
In this article, we are going to learn how to define data when using ggsignif with grouped bar graphs and facet_wrap in R programming language. ggplot2 is a popular R Language package used for data visualization. It allows users to create a wide range of plots and graphs, including bar graphs. However, adding statistical significance bars to bar gr
8 min read
Exploratory Graphs for EDA in R
Exploratory Data Analysis (EDA) is a crucial step in the data science process that helps to understand the underlying structure of a data set. One of the most efficient ways to perform EDA is through the use of graphical representations of the data. Graphs can reveal patterns, outliers, and relationships within the data that may not be immediately
6 min read
Lattice Graphs in R
Lattice graphs in R are a type of graphical representation that uses a grid-like structure to display data. They are commonly used in statistics and data visualization to show the relationship between multiple variables. In R Programming Language, lattice graphs can be created using the lattice package, which provides a variety of functions for cre
6 min read
Saving Graphs as Files in R
In this article, we are going to learn how to save graphs to files in the R programming language. R Saving Graphs as Files Graphs are descriptive R objects which facilitate the visual representation of data in R. The data points become more understandable and readable when expressed in the form of plots. The plots can also be saved within the local
4 min read
How can we make xkcd style graphs in R?
Creating graphs in the distinctive hand-drawn style of XKCD comics can make your data visualizations more engaging and fun. This article will guide you through the process of creating XKCD-style graphs in R using the ggplot2 package along with the xkcd package. What are xkcd style graphs?XKCD, a popular webcomic, often features graphs with a distin
3 min read
R - Line Graphs
A line graph is a chart that is used to display information in the form of a 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. The graph represents differen
3 min read
How to add effect sizes to ggplot bar graphs of t-tests in R?
In this article, we will discuss what Effect sizes are and how they help communicate whether a significant difference is small, moderate, or large, even when the p-value might be statistically significant due to sample size. What is Effect Size?Effect size is a measure of the strength or magnitude of a phenomenon. In the context of a T-test, it hel
4 min read
Convert an Object to List in R Programming - as.list() Function
as.list() function in R Programming Language is used to convert an object to a list. These objects can be Vectors, Matrices, Factors, and dataframes. Syntax: as.list(object) Parameters: object: Vector, Matrix, factor, or data frame R - as.list() Function ExampleExample 1: Converting Vector to list using as.list() function in R Language C/C++ Code #
2 min read
Check if the Object is a List in R Programming - is.list() Function
is.list() function in R Language is used to return TRUE if the specified data is in the form of list, else returns FALSE. Syntax: is.list(X) Parameters: x: different types of data storage Example 1: # R program to illustrate # is.list function # Initializing some list a <- list(1, 2, 3) b <- list(c("Jan", "Feb", "Mar
1 min read
What is the Relation Between R Programming and Hadoop Programming?
The relation between R programming and Hadoop revolves around integrating R with the Hadoop ecosystem to analyze large datasets that are stored in a Hadoop environment. R, primarily used for statistical analysis and data visualization, is not inherently built for handling big data. However, when combined with Hadoop, it can leverage Hadoop's distri
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
Get Exclusive Elements between Two Objects in R Programming - setdiff() Function
setdiff() function in R Programming Language is used to find the elements which are in the first Object but not in the second Object. Syntax: setdiff(x, y) Parameters: x and y: Objects with sequence of itemsR - setdiff() Function ExampleExample 1: Apply setdiff to Numeric Vectors in R Language C/C++ Code # R program to illustrate # the use of setdi
2 min read
Check if Two Objects are Equal in R Programming - setequal() Function
setequal() function in R Language is used to check if two objects are equal. This function takes two objects like Vectors, dataframes, etc. as arguments and results in TRUE or FALSE, if the Objects are equal or not. Syntax: setequal(x, y) Parameters: x and y: Objects with sequence of items Example 1: # R program to illustrate # the use of setequal(
1 min read
Concatenate Two Strings in R programming - paste() method
paste() method in R programming is used to concatenate the two string values by separating with delimiters. Syntax: paste(string1, string2, sep=) Return: Returns the concatenate string. Example 1: # R program to concatenate two strings # Given Strings string1 <- "Geeks" string2 <- "Geeks" # Using paste() method answer <
1 min read
Union of two Objects in R Programming - union() Function
union() function in R Language is used to combine the data of two objects. This function takes two objects like Vectors, dataframes, etc. as arguments and results in a third object with the combination of the data of both the objects. Syntax: union(x, y) Parameters: x and y: Objects with sequence of items Example 1: Union of two Vectors # R program
2 min read
Article Tags :