当前位置:   article > 正文

ggplot常用参数汇总

ggplot clip

作者 | 缪恒

来源 | 量化小城

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

声明:本文内容由网友自发贡献,不代表【wpsshop博客】立场,版权归原作者所有,本站不承担相应法律责任。如您发现有侵权的内容,请联系我们。转载请注明出处:https://www.wpsshop.cn/w/繁依Fanyi0/article/detail/132070
推荐阅读
相关标签
  

闽ICP备14008679号