[{"createTime":1735734952000,"id":1,"img":"hwy_ms_500_252.jpeg","link":"https://activity.huaweicloud.com/cps.html?fromacct=261f35b6-af54-4511-a2ca-910fa15905d1&utm_source=V1g3MDY4NTY=&utm_medium=cps&utm_campaign=201905","name":"华为云秒杀","status":9,"txt":"华为云38元秒杀","type":1,"updateTime":1735747411000,"userId":3},{"createTime":1736173885000,"id":2,"img":"txy_480_300.png","link":"https://cloud.tencent.com/act/cps/redirect?redirect=1077&cps_key=edb15096bfff75effaaa8c8bb66138bd&from=console","name":"腾讯云秒杀","status":9,"txt":"腾讯云限量秒杀","type":1,"updateTime":1736173885000,"userId":3},{"createTime":1736177492000,"id":3,"img":"aly_251_140.png","link":"https://www.aliyun.com/minisite/goods?userCode=pwp8kmv3","memo":"","name":"阿里云","status":9,"txt":"阿里云2折起","type":1,"updateTime":1736177492000,"userId":3},{"createTime":1735660800000,"id":4,"img":"vultr_560_300.png","link":"https://www.vultr.com/?ref=9603742-8H","name":"Vultr","status":9,"txt":"Vultr送$100","type":1,"updateTime":1735660800000,"userId":3},{"createTime":1735660800000,"id":5,"img":"jdy_663_320.jpg","link":"https://3.cn/2ay1-e5t","name":"京东云","status":9,"txt":"京东云特惠专区","type":1,"updateTime":1735660800000,"userId":3},{"createTime":1735660800000,"id":6,"img":"new_ads.png","link":"https://www.iodraw.com/ads","name":"发布广告","status":9,"txt":"发布广告","type":1,"updateTime":1735660800000,"userId":3},{"createTime":1735660800000,"id":7,"img":"yun_910_50.png","link":"https://activity.huaweicloud.com/discount_area_v5/index.html?fromacct=261f35b6-af54-4511-a2ca-910fa15905d1&utm_source=aXhpYW95YW5nOA===&utm_medium=cps&utm_campaign=201905","name":"底部","status":9,"txt":"高性能云服务器2折起","type":2,"updateTime":1735660800000,"userId":3}]
条形图(bar
chart)是用宽度相同的条形的高度或长短来表示数据多少的图形。它主要用来展示不同分类(横轴)下某个数值型变量(纵轴)的取值。在实际中,条形图主要有简单条形图,组合条形图和堆叠条形图。
在R语言的基础包中可以使用barplot()函数来绘制条形图。
R语言中barplot()函数的基本语法格式如下:
barplot(height, names.arg = 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,las=NULL ...)
主要参数的含义如下:
height:向量或矩阵,用来构成条形图中各条的数值。
names.arg:位于条低端的文字标签。
beside: 逻辑值,为FALSE时绘制堆叠图,为TRUE时绘制分组图。
horiz: 逻辑值,为FALSE时,绘制垂直条形图,为TRUE时绘制水平条形图。
density:一个向量值。当指定该值时,条将以斜线填充。即每英寸斜线的密度。
angle:以逆时针方向给出的阴影线的角度。默认为45度。
col:条的填充色。
border:条的边框颜色,如设置为TRUE时,边框颜色将于阴影线的颜色相同。
main:用于指定绘图的主标题。
sub:用于指定绘图的次标题。
xlab, ylab :用于指定x轴和y轴的标签。
xlim, ylim:分别用于指定x轴和y轴的取值范围。
las:las默认是NULL,代表横轴标签都是横着书写,纵轴的标签竖着书写;las=1代表横轴纵轴标签都是横着书写;las=2,代表横轴标签都是竖着书写,纵轴的标签横着书写;las=3,代表横轴纵轴标签都是竖着书写.
举一个示例:
math <- c(78, 92, 89, 61, 95) names<-c("小刚", "小明", "小花", "小芳", "小丽")
barplot(math,names.arg=names,border="green",main="绩",
col=c("red","orange","lightblue","yellow","lightgreen"))
绘图如下: