数据统计与分析基础实验二:可视化绘图(R语言绘图)

实验内容:(本节绘图区间均为I=[自己学号-15自己学号+15])

1、一幅图内同时绘制sin、cos、tan函数曲线图,区间长度为I,三条曲线线型、颜色各不相同。

x<-seq(from=195779-15,to=195779+15,by=1)
y1<-sin(x)
plot(x,y1,xlab="x",ylab="y",ylim=c(-10,10),type='l',col="blue1")
par(new=TRUE)
y2<-cos(x)
plot(x,y2,xlab="x",ylab="y",ylim=c(-10,10),type='p',col="orange2")
par(new=TRUE)
y3<-tan(x)
plot(x,y3,xlab="x",ylab="y",ylim=c(-10,10),type='o',col="red1")
abline(v=x,h=seq(-10,10,by=1),lty=2,col="grey")

leg_tex<-c("sin","cos","tan")
legend(x=195787,y=10.6,leg_tex,col = c("blue1","orange2","red1"),pch=c(15,15,15),text.col = c("blue1","orange2","red1"),horiz=TRUE,title = "图例")

图片由Rstudio导出
在这里插入图片描述

2、绘制三维图形 x = sint-tcost, y = cost-tsint, z = t, t区间为I,图形x、y、z轴均加网格线,z轴取对数分布。

第一种缺点:网格线不全,无法取对数分布
z<-seq(from=195779-15,to=195779+15,by=0.001)
x<-sin(z)-z*cos(z)
y<-cos(z)-z*sin(z)
scatterplot3d(x,y,z,pch = 20,log = "z")

在这里插入图片描述

第二种缺点:无法取对数分布
z<-seq(from=195779-15,to=195779+15,by=0.001)
x<-sin(z)-z*cos(z)
y<-cos(z)-z*sin(z)
scatter3D(x, y, z, 
          phi = 1, 
          col = ramp.col(col = c("cyan", "blue"),),pch =18, 
          cex = 1,  
          ticktype = "detailed",bty = "b2",
          xlim=c(-2e+05,2e+05),ylim=c(-2e+05,2e+05),
          zlim=c(195764,195795))

在这里插入图片描述

3、随机生成一组有效的50人班级的成绩,并绘制合理的统计直方图。提示:1、成绩为整数;2、直方图需选择合适区间。

代码
x<-sample(1:100,50,replace = F)
x
hist(x,xlab = "成绩",ylab= "人数", col = "orange",
     border = "yellow",main = "成绩分布",
     xlim=c(1,100),breaks = 25)
执行结果:
x<-sample(1:100,50,replace = F)
> x
 [1]  65  80  21  75   7  76  26  57  69  16  19  52
[13]   5  58  74   1  46  87  51  86 100  63  12  18
[25]   9  59  89  84  43   6  47  93   3  20  39  92
[37]   4  62  64  28  72  91  66  42  29   8  68  73
[49]  81  53
> hist(x,xlab = "成绩",ylab= "人数", col = "orange",
+      border = "yellow",main = "成绩分布",
+      xlim=c(1,100),breaks = 25)
> 

在这里插入图片描述

4、统计自己十月份的各项支出,并利用软件绘制自己的支出饼状图,采用3种以上方式展示。

代码:
### 1
sales <- c(25,900,50,150,200)
names <- c("网盘费用","饮食","通讯费用","书籍和电子产品","杂项")
pie(sales,main="支出费用",labels=names,col= c("skyblue","lightgreen","red","blue","lightyellow"))
legend("topright",names,cex=0.8,fill = terrain.colors(length(sales)))



### 2

piepercent<-round(100*sales/sum(sales), 1)

piepercent <-paste(piepercent, "%", sep = "")

pie(sales,labels=piepercent, main="支出费用",col= terrain.colors (length(sales)))

legend("topright",names,cex=0.8, fill=terrain.colors(length(sales)))


### 3

pie3D(sales, main="支出费用", labels=piepercent,explode=0.1, radius=1, height=0.05,col= terrain.colors (length(sales)))
legend("topright",names,cex=0.8, fill=terrain.colors(length(sales)))
###
pie3D(sales, main="支出费用", labels=names,explode=0.1, radius=1, height=0.05,col= terrain.colors (length(sales)))
执行结果:

在这里插入图片描述

在这里插入图片描述
在这里插入图片描述

5、绘制散点图x = sint-tcost, y = cost-tsint, t区间为I。

代码:
t<-seq(195779-15,195779+15,by=0.1)
x<-sin(t)-t*cos(t)
y<-cos(t)-t*sin(t)
plot(t,x,xlim =c(195779-15,195779+15),ylab = "x OR y",type="p",col="red")
par(new=TRUE)
plot(t,y,xlim =c(195779-15,195779+15),ylab = "x OR y",type="p",col="blue")
leg_tex<-c("x","y")
legend("topleft",leg_tex,col = c("red","blue"),pch=c(15,15),horiz=TRUE,title = "图例")
abline(v=seq(195779-15,195779+15,by=1),h=seq(-2e+05,2e+05,by=(1e+05)%/%5),lty=2,col="grey")
执行结果:

在这里插入图片描述

6、绘制曲线图、阶梯图x = sint-tcost, y = cost-tsint, t区间为I。

代码:
t<-seq(195779-15,195779+15,by=0.3)
x<-sin(t)-t*cos(t)
y<-cos(t)-t*sin(t)
plot(t,x,xlim =c(195779-15,195779+15),ylab = "x OR y",type="l",col="red")
par(new=TRUE)
plot(t,y,xlim =c(195779-15,195779+15),ylab = "x OR y",type="s",col="blue")
leg_tex<-c("x","y")
legend("topleft",leg_tex,col = c("red","blue"),pch=c(15,15),horiz=TRUE,title = "图例")
abline(v=seq(195779-15,195779+15,by=1),h=seq(-2e+05,2e+05,by=(1e+05)%/%5),lty=2,col="grey")

在这里插入图片描述

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值