ggplot常用参数汇总

作者 | 缪恒

来源 | 量化小城

ggplot整体输入框架:

640?wx_fmt=png

0 1geom_point


ggplot(data =....) +

geom_point(aes(x =..., y =..., color =(类别)..., size =..., alpha(透明度) =...), color =..., shape =..., position ="jitter", ...) + ...


shape样式:

640?wx_fmt=png

02geom_smooth


ggplot(data =....) +

geom_smooth(aes(x =..., y =..., color =(类别)..., linetype =..., group =...,), color =..., size =..., linetype =..., method ="lm",..., formula =..., se = TRUE(展示confidence interval)) + ...


03geom_line


分组线条:

ggplot(data =....) +

geom_line(aes(x =..., y =..., color =(类别)..., linetype =..., group =...,), color =..., size =..., alpha =..., linetype ="...") + ...

linetype样式:

640?wx_fmt=png

特定多组线条

ggplot(data =...., aes(x =...)) +

geom_line(aes(y =..., color =(标签名称)...)size =..., linetype =...+

geom_line(aes(y =..., color =(标签名称)...)size =..., linetype =...+

scale_color_brewer(name =..., palette =...) + ...


04geom_bar


ggplot(data =....) +

geom_bar(aes(x =..., or y =..., color =(类别)..., fill =...), position ="identity", "fill", "dodge"binwidth =..., color =..., fill =..., size =..., linetype ="..."+ ...


05geom_histogram


ggplot(data =....) +

geom_histogram(aes(x =..., or y =..density.., color =(类别)..., fill =...), position ="identity", "fill", "dodge", "jitter", "stack"binwidth =..., bins =..., color =..., fill =..., size =..., linetype ="..."+ ...


06geom_boxplot


ggplot(data =....) +

geom_boxplot(aes(x =..., y =..., color =(类别)..., fill =...), fill =..., notch = TRUEvarwidth =TRUEoutlier.colour =..., outlier.shape =..., stat =...+ ...


07geom_area


ggplot(data =....) +

geom_area(aes(x =..., or y =..density.., color =(类别)..., fill =...), stat ="bin"fill =..., color =..., linetype =...+ ...


08geom_polygon


ggplot(data =....) +

geom_polygon(aes(x =..., y =..., group =..., fill =..., color =...), linetype =...+ ...


09geom_text


ggplot(data =....) +

geom_text(aes(x =..., y =..., label =...,color =(类别)...), data =..., size =..., check_overlap =TRUE, hjust =..., vjust = ..., angle =..., color =...+ ...


10geom_tile


ggplot(data =....) +

geom_tile(aes(x =..., y =..., group =..., fill =...)) + ...


11geom_jitter


ggplot(data =....) +

geom_jitter(aes(x =..., y =..., color =(类别)...)position ="jitter", color =..., alpha =..., size =..., width =...+ ...


12geom_vline/hline/abline


ggplot(data =....) +

geom_hline(yintercept =..., linetype =..., color =..., size =...) /

geom_vline(xintercept =..., linetype =..., color =..., size =...) /

geom_abline(intercept =..., slope =..., linetype =..., color =..., size =...) / + ...


1修改坐标轴


离散型:

scale_x_discrete("坐标轴名称", labels=c("..."="...",...), limits =c(...), breaks =c(...))

连续型:

scale_x_continuous("坐标轴名称",labels=c(...),limits =c(...), breaks =c(...))

library(scale)

scale_x_date(breaks=date_break("1 year"), limits=as.Date(c(...)), labels=date_format("%Y-%m-%d"))


2修改颜色


离散型:

scale_color_manual("图例名称", values =c("名称" = "颜色",...)

scale_fill_manual("图例名称"values =c("名称" = "颜色",...)

scale_color_brewer(name="...", palette ="...")

scale_fill_brewer(name="...", palette ="...")

palette样式:

640?wx_fmt=png

连续型:

scale_color_gradient(low="...", high ="...")

scale_fill_gradient(limits =c(...), low ="...", high ="...")

scale_fill_gradient2(low ="...", high ="...", mid ="...", midpoint =...)


3字体、位置、排版等修改

640?wx_fmt=png四种方程:

element_text(size =..., color =..., face ="bold", angle =..., hjust =..., vjust =...,)

element_line(size =..., color =..., linetype= ...)

element_rect(size =..., color =..., linetype= ..., fill =...)

element_blank()


4主题


640?wx_fmt=png

5分面


640?wx_fmt=png

6其他


放大zooming

coord_cartesian(xlim =c(,), ylim =c(,), expand =TRUE, default =FALSE, clip ="on")

加标题快捷法:

labs(x ="...", y ="...", title ="...")

坐标轴互换:

coord_flip()

图例位置:

theme(legend.position ="top","bottom","left","right")

添加任意方程:

stat_function(fun =..., args =list(,), color =..., size =...)




——————————————

往期精彩:

640?wx_fmt=png

  • 18
    点赞
  • 128
    收藏
    觉得还不错? 一键收藏
  • 1
    评论
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值