为了更加真正的帮助大家理解,博主我去查询翻译了由哈德利·威克姆、丹妮尔·纳瓦罗和托马斯·林·佩德森撰写的《ggplot2:用于数据分析的优雅图形》第三版的在线版本。甄选出了部分核心内容如下:
While this book gives some details on the basics of ggplot2, it’s primary focus is explaining the Grammar of Graphics that ggplot2 uses, and describing the full details. It is not a cookbook, and won’t necessarily help you create any specific graphic that you need. But it will help you understand the details of the underlying theory, giving you the power to tailor any plot specifically to your needs.
虽然本书提供了 ggplot2 基础知识的一些细节,但它的主要重点是解释 ggplot2 使用的图形语法,并描述完整的细节。它不是一本食谱,也不一定能帮助您创建所需的任何特定图形。但它将帮助您了解基本理论的细节,使您能够根据自己的需要专门定制任何情节。
Wiki says “Data visualization is the graphic representation of data.
It involves producing images that communicate relationships among the
represented data to viewers of the images.”
Wiki说: “数据可视化是数据的图形表示。 它涉及制作图像,以将表示的数据之间的关系传达给图像的查看者。”
The inputs we are interested in are:
我们感兴趣的输入是:
Call the ggplot(df) function which creates a blank canvas with the
dataset(df) of interest
调用ggplot(df)函数,该函数将使用感兴趣的数据集(df)创建一个空白画布
Specify aesthetic mappings, which specifies how you want to map
variables to visual aspects. In this case, we are simply mapping the
variables to the x- and y-axes. 指定美学映射,这指定了如何将变量映射到视觉方面。
在这种情况下,我们只是将变量映射到x轴和y轴。
You then add new layers that are geometric objects which will show
up on the plot and additional layers as required.
然后添加作为几何对象的新图层,这些图层将显示在图形上,并根据需要添加其他图层。
Because ggplot2 package isn’t part of the standard distribution of R or R Base, you have to download the package from CRAN(Comprehensive R Archive Network) repository and install it.
由于ggplot2软件包不是R或R Base的标准发行版的一部分,因此您必须从CRAN(综合R存档网络)存储库下载该软件包并进行安装。
Here is how to install a package for the first time with theinstall.packages() function and to load the package at the start of each R session with the library() function.
这是第一次使用install.packages()函数安装软件包,并在每个R会话开始时使用library()函数加载软件包的方法。
To install the ggplot2 package, use the following:
要安装ggplot2软件包,请使用以下命令: