No.14 数据可视化03
主要内容:
- 箱线图
- 散点图矩阵
- 气泡图
- 绘制函数图像
1. 箱线图 boxplot( )
1 2 3 | a <- boxplot (mtcars$wt) a a$stats |
1 | boxplot (wt~vs,data = mtcars) |
1 | boxplot (wt~vs*gear,data = mtcars, col=2:7) |
2. 回归曲线 lowess( )
1 2 3 4 | plot (mtcars$disp,mtcars$wt) #添加回归曲线 #lines() 在原来的图像上画线,lowess() 回归曲线 lines ( lowess (mtcars$wt~mtcars$disp),col= "blue" ) |
3. 散点图矩阵 pairs( ) #描述多个变量之间的关系
1 | pairs (~mpg+disp+wt, data = mtcars) |
1 | pairs (~mpg+disp+wt, data = mtcars, upper.panel= NULL ) #上面的图沿对角线对称 |
1 2 3 | #subset 部分数据 pairs (~mpg+disp+wt, data = mtcars, upper.panel= NULL , col= "blue" , pch=17, subset = vs==1) |
4. 气泡图 symbols() #描述3个变量之间的关系
1 2 | #绘制气泡图,disp为横坐标,wt为纵坐标,mpg的大小用园的半径表示,inches = 0.2代表缩放 symbols (mtcars$disp,mtcars$wt,circles = mtcars$mpg, inches = 0.2) |
1 2 3 4 5 | #对mpg排序 mtcars <- mtcars[ order (mtcars$mpg,decreasing = T),] #绘制气泡图,disp为横坐标,wt为纵坐标,mpg的大小用园的半径表示,inches = 0.2代表缩放 #排序后,bg=heat.colors(32),颜色的深浅表示大小 symbols (mtcars$disp,mtcars$wt,circles = mtcars$mpg, inches = 0.2, bg= heat.colors (32)) |
5. 绘制函数图像 curve( )
1 2 3 | <strong> curve (x^3-3*x,-2,2,n=1000) #add=T表示在上面的曲线上再添加一条曲线,不会覆盖原来的曲线 curve (x^2-2,-2,2,1000,add = T, col=6)</strong> |
6. 颜色搭配
1 | > install.packages ( "RColorBrewer" ) |
#查看包的颜色方案
1 2 | library (RColorBrewer) display.brewer.all () |
1 2 3 | #使用Dark2配色方案中的3个颜色 cols <- brewer.pal (n=3, "Dark2" ) barplot ( c (2,4,7),col = cols) |
【推荐】国内首个AI IDE,深度理解中文开发场景,立即下载体验Trae
【推荐】编程新体验,更懂你的AI,立即体验豆包MarsCode编程助手
【推荐】抖音旗下AI助手豆包,你的智能百科全书,全免费不限次数
【推荐】轻量又高性能的 SSH 工具 IShell:AI 加持,快人一步
· 全程不用写代码,我用AI程序员写了一个飞机大战
· MongoDB 8.0这个新功能碉堡了,比商业数据库还牛
· 记一次.NET内存居高不下排查解决与启示
· DeepSeek 开源周回顾「GitHub 热点速览」
· 白话解读 Dapr 1.15:你的「微服务管家」又秀新绝活了