r - 在 R 中为 Boxplot 添加颜色
问题描述
boxplot(mtcars$mpg ~ mtcars$cyl, main = "Box Plot of Mileage vs Number of Cylinders", xlab = "Number of Cylinders", ylab = "Miles per Gallon", col = "lightgreen")
我有这个代码,所有的盒子都是绿色的,我可以添加什么来使盒子颜色不同
解决方案
您只需要为颜色添加一个因子(x_axis_var)。
boxplot(mtcars$mpg ~ mtcars$cyl,
main = "Box Plot of Mileage vs Number of Cylinders",
xlab = "Number of Cylinders",
ylab = "Miles per Gallon", col = factor(mtcars$cyl))
或提供颜色向量:
boxplot(mtcars$mpg ~ mtcars$cyl,
main = "Box Plot of Mileage vs Number of Cylinders",
xlab = "Number of Cylinders",
ylab = "Miles per Gallon", col = c("blue","red","green"))
推荐阅读
- javascript - 开玩笑 - ReferenceError:没有为简单的测试文件定义定义
- acumatica - Acumatica - 通用查询:链接重定向到自定义页面
- tabulator - 自定义格式列标题/标题的工作示例?
- vba - 如何在链接主字段和子字段中添加 3 个以上的字段?
- python - 制作熊猫系列的直方图
- c# - 停止模拟 IFormFile 创建 FileCopy
- python - 如何使用 read_excel 和 to_excel 格式化 excel 单元格?
- r - 如何为R中列的每个值运行一个函数
- javascript - 用户不输入 0 时的反应输入掩码自定义
- xcode10 - Xcode 10:运行 Set Build Number 脚本失败并显示“没有这样的文件或目录”