I need to plot an histograms and a graph in the same plot. I am having problem with ggplot2 becouse the dataset is very big.
What can I do?
Here an example
lambda=seq(0,1,length.out=100)
b1=lambda^2
b2=lambda^2+1
b=cbind(b1,b2)
perc=rnorm(100)
matplot(lambda,b)
hist(perc)
Thanks for help :D
Sorry my question was not very clear. I need to have the b and the histogram overlapped in the same plot. Something like the plot in this slide.
This time i can not use ggplot becouse the dataset is too big and it takes to much times.
You are not (yet) using ggplot2
, and if you do you will need other commands to control layout, but what i think you want (for base graphics) is the par
command.
lambda=seq(0,1,length.out=100)
b1=lambda^2
b2=lambda^2+1
b=cbind(b1,b2)
perc=rnorm(100)
par(mfrow = c(2,1))
matplot(lambda,b)
hist(perc)
This yields the matplot
as the top chart, and the hist
as the second chart.
If you want side-by-side, use par(mfrow = c(1,2))
.
As noted in the comments, if you want them on top of each other call `par(new = TRUE) in between the plot commands as follows:
matplot(lambda,b)
par(new = TRUE)
hist(perc)
另一个选择是使用TeachingDemos包中的subplot
命令将新绘图添加到现有绘图中。
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.