且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

如何在R中绘制不同颜色的直方图

更新时间:2023-01-27 09:23:29

您需要在 hist 方法中添加 col 参数如下:

You need to add the col arguments in the hist method as follows:

t<- c(69,68,67,65,65,62,59,59,54)
hist(t, main="Distribution of Player Ratings",xlim = c(0,99), 
       breaks=c(seq(40,99,5)), col = c("blue", "red", "gray", "green"))

查看以上执行后得到的图像:

See the image I got after above execution:

现在,您可以根据自己的需要替换颜色值(名称或十六进制值,例如#FFFF00)要求。

Now you can replace the colour values(either name or hexadecimal values like "#FFFF00") as per your requirements.