没有合适的资源?快使用搜索试试~ 我知道了~
R绘画的一般步骤为读取数据,根据需求选择合适的绘画方式。 散点图 箱线图 多窗口绘画 小提琴图 密度曲线图 二维密度曲线图 矩阵散点图 平行坐标图 热力图 直方图 树图 地图
资源推荐
资源详情
资源评论
1. R 基础的数据可视化
(1) 查看点类型及颜色
generateRPointShapes<-function(){
oldPar<-par()
par(font=2,mar=c(0.5,0,0,0))
y=rev(c(rep(0.5,9),rep(1,9),rep(1,5,9)))
x=c(rep(1:9,3))
x=x[1:26]
y=y[1:26]
plot(x,y,pch=0:30,cex=1.5,ylim=c(0,3),xlim=c(1,9.5),
axes=FALSE,xlab="",ylab="",bg="blue")
text(x,y,labels=0:25,pos=3)
par(mar=oldPar$mar,font=oldPar$font)
}
generateRPointShapes()
cl<-colors()
length(cl)
(2)绘制散点图
##读取数据
iris<-read.csv("D:/rdata/chap3/data/Iris.csv")
##可视化散点图
par(family="STKaiti",pch=17)
plot(iris$SepalLengthCm,iris$SepalWidthCm,
type="p",col="red",main="散点图",
xlab="SepalLengthCm",ylab="SepalWidthCm")
(3)多窗口绘画
iris<-read.csv("D:/rdata/chap3/data/Iris.csv")
##可视化多图像窗口
par(family="STKaiti",mfrow=c(2,2))
layout(matrix(c(1,2,3,3),2,2,byrow = TRUE))
hist(iris$SepalLengthCm,breaks=20,col="lightblue",main="直方图",xlab="SepalLengthCm")
smoothScatter(iris$PetalLengthCm,iris$PetalWidthCm,nbin = 64,main="散点图
",xlab="PetalLengthCm",ylab="PetalWidthCm")
##添加第 3 个图像
boxplot(SepalLengthCm~Species,data = iris,main="箱线图",ylab="SepalLengthCm")
2. ggplot2 系列包的可视化
(1) 散点图
Ggplot2 系列的包可以使用+来绘制图像:
library(ggplot2)
library(GGally)
library(gridExtra)
library(dplyr)
##可视化简单的图像
##散点图
p1<-ggplot(iris,aes(x=PetalLengthCm,y=PetalWidthCm))+
theme_bw(base_family = "STKaiti",base_size = 9)+
geom_point(aes(colour=Species))+
labs(title="散点图")
p1
(2) 小提琴图
p2<-ggplot(iris,aes(x=Species,y=SepalLengthCm))+
theme_gray(base_family = "STKaiti",base_size = 9)+
geom_violin(aes(fill=Species),show.legend=F)+
labs(title = "小提琴图")+
theme(plot.title = element_text(hjust = 0.5))
p2
(3) 密度曲线图
p3<-ggplot(iris,aes(SepalWidthCm))+
theme_minimal(base_family = "STKaiti",base_size = 9)+
geom_density(aes(colour=Species,fill=Species),alpha=0.5)+
labs(title = "密度曲线")+
theme(plot.title = element_text(hjust = 0.5),
legend.position = c(0.8,0.8))
p3
(4) 二维密度函数曲线图
p4<-ggplot(iris,aes(x=SepalLengthCm,y=SepalWidthCm))+
theme_classic(base_family = "STKaiti",base_size = 9)+
geom_point(shape=17)+
geom_density_2d(linemitre = 5)+
剩余18页未读,继续阅读
资源评论
mikrokohsm
- 粉丝: 0
- 资源: 1
上传资源 快速赚钱
- 我的内容管理 展开
- 我的资源 快来上传第一个资源
- 我的收益 登录查看自己的收益
- 我的积分 登录查看自己的积分
- 我的C币 登录后查看C币余额
- 我的收藏
- 我的下载
- 下载帮助
最新资源
- python-leetcode面试题解之第198题打家劫舍-题解.zip
- python-leetcode面试题解之第191题位1的个数-题解.zip
- python-leetcode面试题解之第186题反转字符串中的单词II-题解.zip
- 一个基于python的web后端高性能开发框架,下载可用
- python-leetcode面试题解之第179题最大数-题解.zip
- python-leetcode面试题解之第170题两数之和III数据结构设计-题解.zip
- python-leetcode面试题解之第168题Excel表列名称-题解.zip
- python-leetcode面试题解之第167题两数之和II输入有序数组-题解.zip
- python-leetcode面试题解之第166题分数到小数-题解.zip
- python-leetcode面试题解之第165比较版本号-题解.zip
资源上传下载、课程学习等过程中有任何疑问或建议,欢迎提出宝贵意见哦~我们会及时处理!
点击此处反馈
安全验证
文档复制为VIP权益,开通VIP直接复制
信息提交成功