回答
看一看面值
> ?par
> plot(rnorm(100))
> par(new=T)
> plot(rnorm(100), col="red")
随着基础R,你可以画出你的一个曲线,然后用lines()
参数添加第二条曲线。这里有一个简单的例子:
x <- 1:10
y <- x^2
y2 <- x^3
plot(x,y, type = "l")
lines(x, y2, col = "red")
另外,如果你想使用GGPLOT2,这里有两种方法 - 在同一个情节情节不同的颜色,以及其他产生不同的地块为每个变量。这里的技巧是首先将数据“融化”为长格式。
library(ggplot2)
df <- data.frame(x, y, y2)
df.m <- melt(df, id.var = "x")
qplot(x, value, data = df.m, colour = variable, geom = "line")
qplot(x, value, data = df.m, geom = "line")+ facet_wrap(~ variable)
用matplot函数同时绘制多条曲线。帮助(matplot)获得更多。
require(lattice)
x <- seq(-3,3,length.out=101)
xyplot(dnorm(x) + sin(x) + cos(x) ~ x, type = "l")
+1使用格子 – 2010-12-15 11:36:33
还有的是一些解决方案已经为你。如果你使用基础包,你应该熟悉这些功能plot(), lines(), abline(), points(), polygon(), segments(), rect(), box(), arrows(), ...
看看他们的帮助文件。
您应该从基本包中看到一个绘图,并将其作为一个窗格,并显示您给出的坐标。在该窗格上,可以绘制具有上述功能的一整套对象。它们允许您根据需要构建图形。尽管如此,除非您使用Dr. G展示的参数设置进行游戏,否则每次调用plot()都会为您提供一个新窗格。还要考虑到事物可能会被其他事物阴谋诡计,所以想想你用来绘制事物的顺序。
见如:
set.seed(100)
x <- 1:10
y <- x^2
y2 <- x^3
yse <- abs(runif(10,2,4))
plot(x,y, type = "n") # type="n" only plots the pane, no curves or points.
# plots the area between both curves
polygon(c(x,sort(x,decreasing=T)),c(y,sort(y2,decreasing=T)),col="grey")
# plot both curves
lines(x,y,col="purple")
lines(x, y2, col = "red")
# add the points to the first curve
points(x, y, col = "black")
# adds some lines indicating the standard error
segments(x,y,x,y+yse,col="blue")
# adds some flags indicating the standard error
arrows(x,y,x,y-yse,angle=90,length=0.1,col="darkgreen")
这给了你:
GGPLOT2是这样的事情一个很大的包:
install.packages('ggplot2')
require(ggplot2)
x <- 1:10
y1 <- x^2
y2 <- x^3
df <- data.frame(x = x, curve1 = y1, curve2 = y2)
df.m <- melt(df, id.vars = 'x', variable_name = 'curve')
# now df.m is a data frame with columns 'x', 'curve', 'value'
ggplot(df.m, aes(x,value)) + geom_line(aes(colour = curve)) +
geom_point(aes(shape=curve))
你得到的情节有色通过曲线以及每条曲线的不同piont标记,以及一个不错的传说,所有无痛,没有任何额外的工作:
你的代码不会以当前的形式运行。在初始调用'ggplot'之后,你错过了一个parens并引用了错误的对象。这是一个工作版本:' ggplot(df.m,aes(x,value))+ geom_line(aes(color = curve))+ geom_point(aes(shape = curve))' – Chase 2010-12-16 00:04:15
谢谢Chase, sl。。 – 2010-12-16 18:20:13
- 1. 在tkinter的同一个窗口中绘制一个图形和一个表格
- 2. 如何使用R在一个窗口中绘制多个交互式绘图?
- 3. 在ggplot中,如何在同一个窗口中绘制多个图形?
- 4. OpenCV在一个窗口中检测多个对象 - 未绘制
- 5. RStudio - 在多个窗口中的绘图
- 6. 在同一窗口中绘制单独的tkinter数字中的多个图
- 7. 使用matlab在单个窗口中绘制多个图形
- 8. 如何在R中的一个窗口中绘制多个热图R
- 9. C++/Linux - 绘制到一个窗口
- 10. 如何绘制一个窗口框架
- 11. 在同一个OpenGL窗口中绘制2D和3D
- 12. 在pandas或matplotlib的一个图中绘制多个boxplot?
- 13. 动态绘制多个绘图显示在一组轴上(一次绘制一个绘图)
- 14. 在OpenGL中绘制一个绘制调用中的多个VBO
- 15. 在同一个面板中绘制多个直方图
- 16. 在一个图中绘制多个不同类型的ggplots
- 17. 为多个列绘制一个图
- 18. 如何在MATLAB的同一个绘图窗口中绘制两个不同单位(y轴)的曲线?
- 19. Python和Matplotlib:在同一个图上快速绘制多个图
- 20. 如何在PyGame中绘制多个屏幕(仅在一个窗口中)?
- 21. 如何在另一个窗口的窗体中绘制
- 22. 在高图中绘制同一图表上的多个列
- 23. 在同一个图中绘制许多水平条形图
- 24. 无法在同一个图中绘制多条线图
- 25. Python的绘图和显示在同一个GUI窗口
- 26. 在一个图中绘制多个密度图的外包络
- 27. 使用MatLab在单个窗口中绘制3个活动图?
- 28. 在一个PDF上绘制成一个窗口窗体C#(visual studio 2015)
- 29. 如何在同一个面板中绘制多个椭圆
- 30. 在pygame中绘制一个多边形
如果你想要更多的例子,你应该看一看在r图形库(http://addictedtor.free.fr/graphiques/)这是一个很好的来源作为代码的灵感和结果在那里。 – 2010-12-16 19:52:46