生信星球培训第五十九期

学习小组Day4笔记--axin

2020-05-21  本文已影响0人  axin__

R语言基础

安装Rstudio

电脑用户名为英文

Rstudio界面

引自生信星球
引自生信星球

几个命令

R for data science

ggplot(data=mpg) + geom_point (mapping = aes(x=displ,y=hwy))

displ:引擎排量-L 35个,单位为升,小数
hwy:燃油效率:每加仑汽油能跑的公里数(高速路)单位英里/加仑,燃油效率高说明省油。 27个,整数。
class:车型
——生信星球

mpg.png

注:相似语句:
ggplot(data = mpg) + geom_point(mapping = aes(x = displ, y = hwy), color = "blue")
注:color="blue"在aes()外

ggplot(data = mpg) +
geom_point(mapping = aes(x = displ, y = hwy, size = class))
#> Warning: Using size for a discrete variable is not advised.
size = class

警告:不建议将无序变量种类(class)映射为有序图形属性大小(size)。

ggplot(data = mpg) +
geom_point(mapping = aes(x = displ, y = hwy, alpha = class))
Warning message:Using alpha for a discrete variable is not advised. 
alpha = class

警告:不建议将无序变量种类(class)映射为有序图形属性透明度(alpha)。

ggplot(data = mpg) +
geom_point(mapping = aes(x = displ, y = hwy, shape = class))
Warning messages:
1: The shape palette can deal with a maximum of 6 discrete values because more than 6 becomes difficult to discriminate; you have 7.Consider specifying shapes manually if you must have them. 
2: Removed 62 rows containing missing values (geom_point). 
shape = class

警告:ggplot2 只能同时使用 6 种形状,缺失的62行是suv车型没有被分配到形状
验证62:

 count(mpg,class)
# A tibble: 7 x 2
  class          n
  <chr>      <int>
1 2seater        5
2 compact       47
3 midsize       41
4 minivan       11
5 pickup        33
6 subcompact    35
7 suv           62

注:color="blue"在aes()外,原因:

此时颜色不会传达关于变量的信息,只是改变图的外观
要想手动设置图形属性,需要按名称进行设置,将其作为几何对象函数的一个参数。这也就是说,需要在函数 aes() 的外部进行设置。
此外,还需要为这个图形属性选择一个有意义的值"blue"。
——R for data science

上一篇 下一篇

猜你喜欢

热点阅读