barpot:适用于数据表格化后的情形。
barplot(height, width = 1, space = NULL, names.arg = NULL, legend.text = NULL, beside = FALSE, horiz = FALSE, density = NULL, angle = 45, col = NULL, border = par("fg"), main = NULL, sub = NULL, xlab = NULL, ylab = NULL, xlim = NULL, ylim = NULL, xpd = TRUE, log = "", axes = TRUE, axisnames = TRUE, cex.axis = par("cex.axis"), cex.names = par("cex.axis"), inside = TRUE, plot = TRUE, axis.lty = 0, offset = 0, add = FALSE, args.legend = NULL, ...)
参数说明及实例:height:(1)如是向量,则绘制的是条形图。(2)如是矩阵,则绘制堆砌条形图或分组条形图示例:
barplot(c(1,2,3))
width:宽度,控制每个柱子的宽度,默认值为1。值得注意的是,这个参数的值是可以循环使用的,当我们只设置一个值时,会自动循环,生成长度和柱子数目相同的向量,效果就是所有柱子的宽度是一样的,其实也可以指定多个值,使每个柱子的宽度不一样。barplot(c(1,2,3),width=1:3)
space:间隔,指定每个柱子左边的空白区域的宽度,这个值为一个百分比,默认值为0.2, 实际的间隔 = 0.2 * 1(所有柱子的平均宽度) = 0.2; 这个参数的值和width 参数类似,可以只设置一个值,也可以指定不同的柱子间隔不同;
barplot(c(1,2,3),width=1:3,space = c(0.2,0.4,0.6))
names.arg:每个柱子下面的标签,当height 为 vector 时,默认的标记为向量的names 属性, 当height 为 matrix 是,默认为 matrix 的colnames 属性;barplot(c(1,2,3),width=1:3,space = c(0.2,0.4,0.6),names.arg=c("a","b","c"))
legned.text : 图例。仅在height参数值是matrix 时使用,默认显示的是matrix的rownames 属性,其值有两种指定形式;
barplot(matrix(1:4,nrow = 2,ncol = 2),legend.text=c("a","b"))
density:柱子中斜线填充的密度;
angle:斜线的角度,默认是45度;
par(mfrow=c(1,2))
barplot(c(1,2,3),beside = TRUE,density=10,main = "density=10")
barplot(c(1,2,3),beside = TRUE,density=20,angle=90,main = "density=20")
axes:逻辑值,控制是否显示坐标轴;
axisnames : 逻辑值,控制是否显示柱子的标签;
par(mfrow=c(1,2))
barplot(c(1,2,3),beside = TRUE,axes = FALSE,names.arg=c("a","b","c"),axisnames = FALSE,main = "axes = FALSE & axisnames = FALSE")
barplot(c(1,2,3),beside = TRUE,axes = TRUE,names.arg=c("a","b","c"),axisnames = TRUE,main = "axes = TRUE & axisnames = TRUE")
暂无数据