如何在基本 R 图中更改图例的背景颜色?


要在基本 R 中为绘图创建图例,我们可以使用 legend 函数,如果图例的背景颜色需要从白色更改为其他颜色,则将使用 legend 函数中的 bg 参数。例如,要将背景颜色更改为红色,我们可以使用 bg="red"。

示例 1

 实时演示

plot(1:10)
legend("right",legend="point chart",bg="blue")

输出

Explore our latest online courses and learn new skills at your own pace. Enroll and become a certified expert to boost your career.

示例 2

 实时演示

plot(1:10)
legend("right",legend="point chart",bg="light green")

输出

示例 3

 实时演示

plot(1:10)
legend("left",legend="point chart",bg="light grey")

输出

更新日期: 2021 年 2 月 5 日

2 千次浏览

开启你的 职业

完成课程后获得认证

开始学习
广告