美文网首页
第3章 工具箱

第3章 工具箱

作者: iBioinformatics | 来源:发表于2023-03-08 10:38 被阅读0次
> 
> mpg
# A tibble: 234 x 11
   manufacturer model      displ  year   cyl trans      drv     cty   hwy fl    class  
   <chr>        <chr>      <dbl> <int> <int> <chr>      <chr> <int> <int> <chr> <chr>  
 1 audi         a4           1.8  1999     4 auto(l5)   f        18    29 p     compact
 2 audi         a4           1.8  1999     4 manual(m5) f        21    29 p     compact
 3 audi         a4           2    2008     4 manual(m6) f        20    31 p     compact
 4 audi         a4           2    2008     4 auto(av)   f        21    30 p     compact
 5 audi         a4           2.8  1999     6 auto(l5)   f        16    26 p     compact
 6 audi         a4           2.8  1999     6 manual(m5) f        18    26 p     compact
 7 audi         a4           3.1  2008     6 auto(av)   f        18    27 p     compact
 8 audi         a4 quattro   1.8  1999     4 manual(m5) 4        18    26 p     compact
 9 audi         a4 quattro   1.8  1999     4 auto(l5)   4        16    25 p     compact
10 audi         a4 quattro   2    2008     4 manual(m6) 4        20    28 p     compact
# ... with 224 more rows

3.5.4 匹配图形属性与图形对象

离散型变量

library(ggplot2)
ggplot(mpg,aes(class))+ geom_bar()
ggplot(mpg,aes(class,fill=drv))+ geom_bar()

连续型变量

ggplot(mpg,aes(class,fill=hwy))+ geom_bar()
ggplot(mpg,aes(class,fill=hwy,group=hwy))+ geom_bar()

3.11 展示数据分布

ggplot(diamonds,aes(depth))+
 geom_freqpoly(binwidth=0.1,na.rm=TRUE)+xlim(58,68)+
 theme(legend.position="none")

## aes(colour=cut)
ggplot(diamonds,aes(depth))+
 geom_freqpoly(aes(colour=cut),binwidth=0.1,na.rm=TRUE)+xlim(58,68)+
 theme(legend.position="none")

## geom_histogram(aes(fill=cut))
ggplot(diamonds,aes(depth))+ 
 geom_histogram(aes(fill=cut),binwidth=0.1,na.rm=TRUE)+xlim(58,68)+
 theme(legend.position="none")


## 加上 position="fill"
ggplot(diamonds,aes(depth))+ 
 geom_histogram(aes(fill=cut),binwidth=0.1,position="fill",na.rm=TRUE)+xlim(58,68)+
 theme(legend.position="none")

相关文章

网友评论

      本文标题:第3章 工具箱

      本文链接:https://www.haomeiwen.com/subject/ztcyldtx.html