R是用于统计分析、绘图的语言和操作环境。这里介绍如何使用R语言的ggplot2扩展包生成图形。
我们首先使用R语言的pressure数据集和qlpot()函数来个简单的例子:
> library(ggplot2)
> qplot(temperature,pressure,data = pressure)
再使用qplot()来一个稍微复杂一点的图形
> qplot(temperature,pressure,data = pressure,
main = "水银蒸汽压力",
geom=c("point","line"))
这里添加了main属性,就是图片的标题,还指定了作图的方法是使用点和线。
不过可以看出这里的直线是点与点之间连起来的,如果我们想要一条光滑的曲线怎么办?只要把line改成smooth就可以了。
> qplot(temperature,pressure,data = pressure,
main = "水银蒸汽压力",
geom=c("point","smooth"))
当然ggplot2的qplot()函数的设置起来会让图形更高大上,更多内容会在下一篇文章中介绍