一、条形图
1.安装包install.packages("vcd");
library(vcd);
count<-table(Arthritis$Improved);#table统计病人的提高情况(表格化)。
barplot(count,main="Bar plot",xlab="Imrovement",ylab="count")#水平图
barplot(count,main="Bar plot",xlab="Imrovement",ylab="count",horiz=TRUE)#垂直图
#分组条形图
count<-table(Arthritis$Improved,Arthritis$Treatment);
barplot(count,main = "堆砌条形图",xlab="Treatment",ylab="F",col=c("red","yellow","green"),legend=rownames(count));
barplot(count,main = "分组条形图",xlab="Treatment",ylab="F",col=c("red","yellow","green"),legend=rownames(count),beside=TRUE);
spine(count,main="Spinogram Example");#
#饼图pie(x,labels)
count<-table(Arthritis$Improved);#table统计病人的提高情况(表格化)。
pie(count);
count
library("plotrix")
lab<-c("none","some","marked");
pie3D(count,labels = lab,explode = 0.1);#三维拼图
##直方图
par(mfrow=c(2,1));
dat<-A$Age
hist(dat);#最简单的直方图
hist(dat,
breaks = 20,
col = "green",
xlab = "age",
ylab = "cout",
main = "ages")
rug(dat)#添加轴点;
lines(density(dat),col="red",lwd=2)#添加轴线
x<-dat;
box();
#核密度图plot(density)
par(mfrow=c(2,1));
plot(density(dat));
polygon(density(dat),col="red",border="blue");#填充颜色
rug(dat,col="brown");
box();
#箱图boxplot(最小值,下四分位数,中位数,上四分位数,最大值)
boxplot(A,notch=TRUE);#中notch为画出凹图
boxplot.stats(dat);
##小提琴图整体貌似小提琴,外部形状为核密度估计。
install.packages("vioplot");
library(vioplot)
vioplot(A$Age,A$ID,names=c("age","ID"),col="red");
#点图dotchart(x,labels=)
dotchart(dat);