M守护神 2020-06-09
语法
在R语言中创建条形图的基本语法是------
barplot(H,xlab,ylab,main,names.arg,col)
以下是所使用的参数的描述——
H是包含在条形图中使用的数值的向量或矩阵。
xlab是x轴的标签。
ylab是y轴的标签。
main是条形图的标题。
names.arg是在每个条下出现的名称的向量。
col用于向图中的条形提供颜色。
#R语言条形图
#Create the data for the chart.
H <- c(7,12,28,3,41)
M <- c("Mar","Apr","May","Jun","Jul")
#Give the chart file a name.
png(file="G:\\R学习笔记\\barchart_months_revenue.png")
#Plot the bar chart.
barplot(H,names.arg=M,xlab="Month",ylab="Revenue",col="blue",main="Revenue chart",border="red")
#Save the file.
#dev.off() 判断当前图片输出设备是否有可用的,如果没有那也不用执行dev.off()这句话了
while (!is.null(dev.list())) dev.off()当执行完上述代码产生以下效果:
