R中的ggplot和basic plot有什么区别? [英] What's the difference between ggplot and basic plot in R?

查看:655
本文介绍了R中的ggplot和basic plot有什么区别?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

对于在R中绘制图形,我通常使用软件包graphics中的基本曲线plot()barplot()boxplot() ...函数.但是ggplot似乎更经常使用.

For plotting graphs in R, I usually use basic plot plot(), barplot(), boxplot()... functions from the package graphics. But ggplot seemed to be used more often.

在选择使用哪种图形时,要考虑的两种图形之间的主要区别是什么?

What are the main differences between the two types of graphics to take into account when choosing which one to use ?

推荐答案

基本绘图范例是纸上写的",而latticeggplot范例基本上是在编写使用网格程序包完成程序的程序.低级输出到目标图形设备. ggplot-范例具有图形语法"设计,该设计试图将各种不同的绘图功能集成到一个连贯的程序包中.它确实需要加载ggplot2软件包,而R会以已经加载的graphicsgrDevices软件包启动.当在函数内部使用ggplot2lattice函数时,都需要使用显式的print调用.

The base plotting paradigm is "ink on paper" whereas the lattice and ggplot paradigms are basically writing a program that uses the grid-package to accomplish the low-level output to the target graphics devices. The ggplot-paradigm has the "Grammar of Graphics" design which tries to integrate a variety of different plotting functions into one coherent package. It does require loading the ggplot2 package, whereas R starts up with the graphics and grDevices packages already loaded. Both ggplot2 and lattice functions require the use of an explicit print call when they are used inside a function.

使用ggplot2,您可以将该函数的结果分配给对象名称,然后进一步对其进行修改.准备好进行发布"时,您将处理输出并将其发送到带有打印的设备.通常,通过使用+.gg函数,通过在使用qplotggplot创建的基本图中添加图层",可以逐步修改"ggplot"图形.

With ggplot2 you assign the result of that function to an object name and then further modify it. When it's ready for "publication" you get the output processed and sent to a device with print. "ggplot" graphics often get progressively modified by adding "layers" to a base plot created with qplot or ggplot through the use of the +.gg-function.

base图形的情况下,没有保存结果的R对象.这些命令将立即得到处理,并刻在当前设备的纸"上.然后,您发出其他命令来增加该设备上的输出. plotrix软件包为使用base -graphics范例开发高级绘图设备提供了一个很好的例子.

In the case of base-graphics there is no R object that holds results. The commands get processed immediately and inscribed on the "paper" of the current device. You then issue further commands to augment the output on that device. The plotrix package gives a good example of the development of advanced plotting facilities using the base-graphics paradigm.

ggplot2功能与baselattice图形功能的一个主要限制是ggplot2没有任何3D绘图功能.但是,lattice -package并未得到积极维护,但在停止积极开发的时刻,它似乎已经相当成熟,如果您发现错误,则很可能已将其修复. gridExtralatticeExtra软件包都扩展了grid和ggplot2功能.现在还有一个gridBase程序包,它支持将基础绘图结果保存为网格"grob",然后合并基础和网格(即latticeggplot)输出.的确,"ggplot"范式似乎是近年来更持续活动的目标.

One major limitation of ggplot2-functions versus base and lattice graphics functions is that ggplot2 does not have any 3D plotting functions. The lattice-package, however, is not being actively maintained, but it seemed fairly mature at the point that active development was stopped and if you find a bug it will probably be fixed. There are both the gridExtra and latticeExtra packages that extend lattice and ggplot2 capabilities. There is now also a gridBase package that supports saving base plotting results as a grid "grob" and then merging base and grid, i.e. lattice or ggplot, output. It is certainly true that "ggplot"-paradigm seems to be the target of more sustained activity in recent years.

这篇关于R中的ggplot和basic plot有什么区别?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆