Quantcast
Channel: Plot two graphs in a same plot - Stack Overflow
Browsing latest articles
Browse All 18 View Live
↧

Image may be NSFW.
Clik here to view.

Answer by DiegoJArg for Plot two graphs in a same plot

Use curve for mathematical functions.And use add=TRUE to use the same plot and axis.curve( log2 , to=5 , col="black", ylab="log's(.)")curve( log , add=TRUE , col="red" )curve( log10, add=TRUE ,...

View Article


Image may be NSFW.
Clik here to view.

Answer by Saurabh Chauhan for Plot two graphs in a same plot

Using plotly (adding solution from plotly with primary and secondary y axis- It seems to be missing):library(plotly) x <- seq(-2, 2, 0.05)y1 <- pnorm(x)y2 <- pnorm(x, 1,...

View Article


Image may be NSFW.
Clik here to view.

Answer by Varn K for Plot two graphs in a same plot

we can also use lattice librarylibrary(lattice)x <- seq(-2,2,0.05)y1 <- pnorm(x)y2 <- pnorm(x,1,1)xyplot(y1 + y2 ~ x, ylab = "y1 and y2", type = "l", auto.key = list(points = FALSE,lines =...

View Article

Image may be NSFW.
Clik here to view.

Answer by Alessandro Jacopson for Plot two graphs in a same plot

Idiomatic Matlab plot(x1,y1,x2,y2) can be translated in R with ggplot2 for example in this way:x1 <- seq(1,10,.2)df1 <- data.frame(x=x1,y=log(x1),type="Log")x2 <- seq(1,10)df2 <-...

View Article

Image may be NSFW.
Clik here to view.

Answer by epo3 for Plot two graphs in a same plot

You can also create your plot using ggvis:library(ggvis)x <- seq(-2, 2, 0.05)y1 <- pnorm(x)y2 <- pnorm(x,1,1)df <- data.frame(x, y1, y2)df %>% ggvis(~x, ~y1, stroke := 'red') %>%...

View Article


Image may be NSFW.
Clik here to view.

Answer by isomorphismes for Plot two graphs in a same plot

tl;dr: You want to use curve (with add=TRUE) or lines.I disagree with par(new=TRUE) because that will double-print tick-marks and axis labels. EgThe output of plot(sin); par(new=T); plot( function(x)...

View Article

Answer by MLow for Plot two graphs in a same plot

if you want to split the plot into two columns (2 plots next to each other), you can do it like this:par(mfrow=c(1,2))plot(x)plot(y) Reference Link

View Article

Answer by Spacedman for Plot two graphs in a same plot

Use the matplot function:matplot(x, cbind(y1,y2),type="l",col=c("red","green"),lty=c(1,1))use this if y1 and y2 are evaluated at the same x points. It scales the Y-axis to fit whichever is bigger (y1...

View Article


Answer by user3749764 for Plot two graphs in a same plot

I think that the answer you are looking for is:plot(first thing to plot)plot(second thing to plot,add=TRUE)

View Article


Image may be NSFW.
Clik here to view.

Answer by Mateo Sanchez for Plot two graphs in a same plot

You could use the ggplotly() function from the plotly package to turn any of the gggplot2 examples here into an interactive plot, but I think this sort of plot is better without ggplot2:# call Plotly...

View Article

Image may be NSFW.
Clik here to view.

Answer by Henrik for Plot two graphs in a same plot

As described by @redmode, you may plot the two lines in the same graphical device using ggplot. In that answer the data were in a 'wide' format. However, when using ggplot it is generally most...

View Article

Image may be NSFW.
Clik here to view.

Answer by redmode for Plot two graphs in a same plot

When constructing multilayer plots one should consider ggplot package. The idea is to create a graphical object with basic aesthetics and enhance it incrementally.ggplot style requires data to be...

View Article

Answer by brainstorm for Plot two graphs in a same plot

You can use points for the overplot, that is.plot(x1, y1,col='red')points(x2,y2,col='blue')

View Article


Answer by cranberry for Plot two graphs in a same plot

Rather than keeping the values to be plotted in an array, store them in a matrix. By default the entire matrix will be treated as one data set. However if you add the same number of modifiers to the...

View Article

Answer by Sam for Plot two graphs in a same plot

You can also use par and plot on the same graph but different axis. Something as follows:plot( x, y1, type="l", col="red" )par(new=TRUE)plot( x, y2, type="l", col="green" )If you read in detail about...

View Article


Answer by mcabral for Plot two graphs in a same plot

If you are using base graphics (i.e. not lattice/ grid graphics), then you can mimic MATLAB's hold on feature by using the points/lines/polygons functions to add additional details to your plots...

View Article

Answer by bnaul for Plot two graphs in a same plot

lines() or points() will add to the existing graph, but will not create a new window. So you'd need to doplot(x,y1,type="l",col="red")lines(x,y2,col="green")

View Article


Plot two graphs in a same plot

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...

View Article
Browsing latest articles
Browse All 18 View Live


<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>