当前位置:   article > 正文

R语言学习-tidyverse-ggplot2入门

R语言学习-tidyverse-ggplot2入门

ggplot2介绍

ggplot2包由Hadley Wickham(2009a)编写,它提供了一种基于Wilkinson(2005)所描述的图形语法的图形系统,Wickham(2009b)还对该语法进行了扩展。ggplot2包的目标是提供一个全面的、基于语法的、连贯一致的图形生成系统,允许用户创建新颖的、有创新性的数据可视化图形。

ggplot2中,图通过+串联函数而创建,每个函数负责自己的部分。

ggplot(by_year_continent, aes(x = year, y = medianGdpPercap, color = continent, size = pop))+
geom_point()+       #点图
expand_limits(y = 0) +    #y轴从0开始
scale_x_log10() +     #x轴做log转换
labs(title = "plot1", x= "year", y = "median of GDP per cap")
  • 1
  • 2
  • 3
  • 4
  • 5

几何函数

函数添加选项
geom_bar()条形图1 the height of the bar proportional to the number of cases in each groupcolor, fill, alpha
geom_col()条形图2 the heights of the bars represents values in the datacolor, fill, alpha
geom_boxplot()箱线图color, fill, alpha, notch, width
geom_density()密度图color, fill, alpha, linetype
geom_histogram()直方图color, fill, alpha, linetype, binwidth
geom_hline()水平线color, alpha, linetype, size
geom_jitter()抖动点color, size, alpha, shape
geom_line()线图color, alpha, linetype, size
geom_point()散点图color, alpha, shape, size
geom_rug()地毯图color, side
geom_smooth()拟合曲线method, formula, color, fill, linetype, size
geom_text()文字注解很多,参见函数的“帮助”
geom_violin()小提琴图color, fill, alpha, linetype
geom_vline()垂线color, alpha, linetype, size
声明:本文内容由网友自发贡献,不代表【wpsshop博客】立场,版权归原作者所有,本站不承担相应法律责任。如您发现有侵权的内容,请联系我们。转载请注明出处:https://www.wpsshop.cn/w/不正经/article/detail/270609
推荐阅读
相关标签
  

闽ICP备14008679号