R可视化:ggplot2的基本原理和使用方法

Python014

R可视化:ggplot2的基本原理和使用方法,第1张

ggplot2是R语言第三方可视化扩展包,在某种程度上它基本代替了R可视化。该包是RStudio首席科学家Hadley Wickham读博期间的作品,它强大的画图逻辑使得它称为R最流行的包之一。更多知识分享请到 https://zouhua.top/

ggplot2 is based on the grammar of graphics, the idea that you can build every graph from the same few components: a data set, a set of geoms—visual marks that represent data points, and a coordinate system。

To display data values, map variables in the data set to aesthetic properties of the geom like size, color, and x and y locations

aesthetic map variables in data to graphic properties. mappings control the relationship between data and graphic properties.

Aesthetic mapping means "something you can see"

Each type of geom accepts only a subset of all aesthetics-refer to the geom help pages to see what mappings each geom accepts. Aesthetic mappings are set with the aes() function.

scales map values in the data space to values in the aesthetic space(color, size, shape ...). scales are reported on the plot using axes and legends. Control aesthetic mapping.

Scales are modified with a series of functions using a scale_<aesthetic>_<type>naming scheme

The following arguments are common to most scales in ggplot2:

geometric objects are the actual marks we put on a plot

A plot must have at least one geometric object, and there is no upper limit. adding a geom by using the + operator.

It's often useful to transform your data before plotting, and that's what statistical transformations do.

Every geom function has a default statistic:

The ggplot2 theme system handles non-data plot elements such as

Built-in themes include:

在matlab产生的图像窗口中(如figure1),点击edit---axes properties,在下面的x axis中点击ticks,在x tick locations中选择step by,输入0.01,其他的自己类比着调整就行了