image.png
一.认识R和Rstudio
- plot: plot(y)、plot(x,y)、plot(x1,y1,x2,y2,……)
plot(rnorm(50))
plot(rnorm(50))
- runif() 用于创建均匀分布的随机偏差。
用法: runif(n, min, max)
参数:
n:表示观察次数
min, max:表示分布的下限和上限
范例1:
# Create uniform distribution between range -1 to 1
x <- runif(20, min = -1, max = 1)
# Print distibution
print(x)
[1] -0.8675158 0.1340688 0.2893207 0.5708924 -0.3839657
[6] 0.5069728 0.2875845 -0.6167163 0.3563724 -0.4103136
[11] 0.7826382 0.1276890 0.5538205 0.1080454 -0.6723669
[16] 0.5441801 -0.4648752 -0.9905739 0.1540437 -0.5027371
- boxplot
# iris$Sepal.Length表示iris数据框的Sepal.Length这一列数据
boxplot(iris$Sepal.Length~iris$Species,col = c("lightblue","lightyellow","lightpink"))
箱线图练习
二、设置字体大小
外观设置
三、R语言基本操作
1.用Rproject管理工作目录:默认的读取和储存位置
2.显示文件列表
dir()
list.files()
3.加减乘除
4.赋值 <- : 'ALT' + '-'
5.删除变量 rm ;清空所有变量 rm(list = ls())
a<-3
b <- 1
c <- 4
u <- 5+6
rm(b)
rm(u,c)
rm(list = ls())
6.列出历史命令 : history()
history()
7.清空控制台 : 快捷键ctrl+l
R数据科学--详解ggplot2
R for Data Science
R for Data Science