ggplot常用的参数
ggplot(data = <DATA>) +
<GEOM_FUNCTION>(
mapping = aes(<MAPPINGS>),
stat = <STAT>,
position = <POSITION>
) +
<COORDINATE_FUNCTION> +
<FACET_FUNCTION>
DATA :数据源
GEOM_FUNCTION: 几何对象(你要画什么类型的图)
MAPPINGS :映射函数
STAT :统计变换(stat = 'identity’或者stat = 'count’后者为默认,条形图中使用)
POSITION :位置调整(条形图:堆叠,填充,分组)
COORDINATE_FUNCTION:坐标轴调整(极坐标,条形图变扇形图)
FACET_FUNCITON:分面函数
图形映射属性
1、常用映射
library(tidyverse)
#颜色映射
mpg %>%
ggplot(data = mpg) +
geom_point(mapping = aes(x = displ, y = hwy, color = class)
#size大小映射
ggplot(data = mpg) +
geom_point(mapping = aes(x = displ, y = hwy, size = class)
#透明度alpha映射
ggplot(data = mpg) +
geo