# Plot two graphs in same plot in R

###### Posted By: Anonymous

I would like to plot y1 and y2 in the same plot.

```
x <- seq(-2, 2, 0.05)
y1 <- pnorm(x)
y2 <- pnorm(x, 1, 1)
plot(x, y1, type = "l", col = "red")
plot(x, y2, type = "l", col = "green")
```

But when I do it like this, they are not plotted in the same plot together.

In Matlab one can do `hold on`

, but does anyone know how to do this in R?

## Solution

`lines()`

or `points()`

will add to the existing graph, but will not create a new window. So you’d need to do

```
plot(x,y1,type="l",col="red")
lines(x,y2,col="green")
```

###### Answered By: Anonymous

### Related Articles

- Graph visualization library in JavaScript
- A tool to convert MATLAB code to Python
- How to prevent scrolling the whole page?
- What can MATLAB do that R cannot do?
- Best way to extract messy HTML tables using BeautifulSoup
- Differences between Octave and MATLAB?
- Tensorflow: how to save/restore a model?
- R: `Error in xy.coords(x, y) : 'x' and 'y' lengths differ`
- Using setInterval for creating animation
- Deleting document from Firestore based on array key
- Drawing a simple line graph in Java
- how to add nodes and links do d3-force without enter
- How to make a Graph on VueJS
- Continuous Convolution Using 3 Different Methods in…
- What is MATLAB good for? Why is it so used by…
- Flatten points into SVG polyline Polymer
- How can I plot with 2 different y-axes?
- integrating disqus with emberjs only works on first…
- Ukkonen's suffix tree algorithm in plain English
- Dafny prove lemmas in a high-order polymorphic function
- Smart way to truncate long strings
- Difference between variable declaration syntaxes in…
- CSS selector for first element with class
- How do I put variable values into a text string in MATLAB?
- A simple explanation of Naive Bayes Classification
- How to use hex color values
- How can I make a "color map" plot in matlab?
- How to map values in a dataframe to a key with…
- Difference between a Seq and a List in Scala
- Twitter Bootstrap tabs not working: when I click on…
- making matplotlib scatter plots from dataframes in…
- Why does this ember component not render?
- How to change the window title of a MATLAB plotting figure?
- Fastest way to pad a dataframe with uneven columns
- How can I determine whether a 2D Point is within a Polygon?
- gnuplot : plotting data from multiple input files in…
- Mutate column using array names
- What is your most productive shortcut with Vim?
- How do you create vectors with specific intervals in R?
- Use superscripts in R axis labels
- Set Colorbar Range in matplotlib
- collision detection from picturebox in a list c#
- How to get all files under a specific directory in MATLAB?
- Something is wrong with my if and else statement
- Making Adjacency List in Scala with FoldLeft
- Add new row to dataframe, at specific row-index, not…
- opencv align two images by keypoints with stretching
- Python equivalent to 'hold on' in Matlab
- polymer on-hold event is far too short, is there a…
- How to specify the actual x axis values to plot as x…
- How to combine 2 ggplot graph?
- Smoothing a curve with vectors made by few elements?
- Getting the value of a paper-radio-button inside a template
- Remove the zero line from ggplot2
- How to create an executable .exe file from a .m file
- Plot graph with vertical labels on the x-axis Matplotlib
- SICP 3.52 delayed cdr
- How to sort coordinates in python in a clockwise direction
- Vuetify grid system row management
- Random meetings in large graphs: efficient way of…
- How to apply rolling t.test with pandas?
- C++ Passing Pointer to Function (Howto) + C++…
- SQL query return data from multiple tables
- Error in plot.new() : figure margins too large in R
- Merge list of results into a single variable with Python
- How can I create a horizontal bar chart in R that is…
- How to define partitioning of DataFrame?
- How to create a dynamic form vuejs vuetify?
- Highchart in new window
- Polymer, SVG path, Internet Explorer
- How to use html template with vue.js
- Plotting multiple curves same graph and same scale
- facebook: permanent Page Access Token?
- React client tries to access server resource without…
- Gnuplot, change the color of data points and x-axis
- IE8 issue with Twitter Bootstrap 3
- Understanding Matlab FFT example
- How to retrieve the current value of an oracle…
- Java time-based map/cache with expiring keys
- ggplot2 line chart gives "geom_path: Each group…
- Checkbox Validation Without Arrow Functions using Svelte
- Renaming column names of a DataFrame in Spark Scala
- Javascript validate all checkboxes are selected
- Is there a foreach in MATLAB? If so, how does it…
- Backbone.js - Loading views programmatically
- Managing longs and short orders like LucF PineCoders…
- How to print an AST from a parser generator to graphviz?
- What are the undocumented features and limitations…
- How to iterate over a column vector in Matlab?
- How to normalize a vector in MATLAB efficiently? Any…
- Create Bullet Graph using ggplot2 or plotly in R
- How to add a line to a multiline TextBox?
- How to trace the path in a Breadth-First Search?
- Adding a legend to PyPlot in Matplotlib in the…
- Bootstrap 4 card-deck with number of columns based…
- Get user profile picture by Id
- Automatically plot different colored lines
- How to import Proj4js to use with Highmaps?
- Circular Dependency with two depending Services
- Label points in section of np.meshgrid

Disclaimer: This content is shared under creative common license cc-by-sa 3.0. It is generated from StackExchange Website Network.