R语言ColorPalette

因加颜色致显示分类不全,如何拓展R语言色板

1. 拓展颜色

此处颜色导致显示cluster显示不全,若遇到brewer.pal无法加足够数量cluster的颜色显示的话,可以尝试使用colorRampPalette函数进行颜色拓展。
例如传统Brewer.pal: Paired颜色为12个
在这里插入图片描述

col<-colorRampPalette(brewer.pal(12,'Paired'))(30)

将12个颜色拓展到30个颜色
也可以用blue,white,red来筛选相关的颜色
在这里插入图片描述

2. rainbow函数

若不嫌太丑也可以使用rainbow函数

col<-rainbow(30)

3. Paletteer

paletteer_c("scico::berlin", 100)

在这里插入图片描述

下面是一个使用AWT和GridLayout布局管理器设计的调色板界面,其中包含三个滑动条分别用于调整红、绿、蓝三种颜色的值,加减按钮用于改变颜色值中各色值的分量,下面的面板会与之同步改变。 ```java import java.awt.*; import java.awt.event.*; public class ColorPalette extends Frame implements AdjustmentListener, ActionListener { private Scrollbar redScrollbar, greenScrollbar, blueScrollbar; private Label redLabel, greenLabel, blueLabel; private Button plusRedButton, minusRedButton, plusGreenButton, minusGreenButton, plusBlueButton, minusBlueButton; private Panel colorPanel; public ColorPalette() { super("Color Palette"); // 创建三个滑动条和对应的标签 redScrollbar = new Scrollbar(Scrollbar.HORIZONTAL, 127, 1, 0, 255); greenScrollbar = new Scrollbar(Scrollbar.HORIZONTAL, 127, 1, 0, 255); blueScrollbar = new Scrollbar(Scrollbar.HORIZONTAL, 127, 1, 0, 255); redLabel = new Label("R: " + redScrollbar.getValue()); greenLabel = new Label("G: " + greenScrollbar.getValue()); blueLabel = new Label("B: " + blueScrollbar.getValue()); // 创建加减按钮 plusRedButton = new Button("+"); minusRedButton = new Button("-"); plusGreenButton = new Button("+"); minusGreenButton = new Button("-"); plusBlueButton = new Button("+"); minusBlueButton = new Button("-"); // 创建颜色面板 colorPanel = new Panel(); colorPanel.setBackground(new Color(redScrollbar.getValue(), greenScrollbar.getValue(), blueScrollbar.getValue())); // 设置布局管理器 setLayout(new GridLayout(4, 3)); // 添加组件 add(redLabel); add(redScrollbar); add(plusRedButton); add(greenLabel); add(greenScrollbar); add(plusGreenButton); add(blueLabel); add(blueScrollbar); add(plusBlueButton); add(new Label()); add(new Label()); add(minusRedButton); add(new Label()); add(new Label()); add(minusGreenButton); add(new Label()); add(new Label()); add(minusBlueButton); add(new Label()); add(new Label()); add(colorPanel); // 添加事件监听器 redScrollbar.addAdjustmentListener(this); greenScrollbar.addAdjustmentListener(this); blueScrollbar.addAdjustmentListener(this); plusRedButton.addActionListener(this); minusRedButton.addActionListener(this); plusGreenButton.addActionListener(this); minusGreenButton.addActionListener(this); plusBlueButton.addActionListener(this); minusBlueButton.addActionListener(this); // 设置窗口大小和可见性 setSize(400, 200); setVisible(true); } public void adjustmentValueChanged(AdjustmentEvent e) { // 更新颜色面板和标签的颜色值显示 colorPanel.setBackground(new Color(redScrollbar.getValue(), greenScrollbar.getValue(), blueScrollbar.getValue())); redLabel.setText("R: " + redScrollbar.getValue()); greenLabel.setText("G: " + greenScrollbar.getValue()); blueLabel.setText("B: " + blueScrollbar.getValue()); } public void actionPerformed(ActionEvent e) { // 根据按钮的不同,改变对应颜色值滑动条的值 if (e.getSource() == plusRedButton) { redScrollbar.setValue(redScrollbar.getValue() + 1); } else if (e.getSource() == minusRedButton) { redScrollbar.setValue(redScrollbar.getValue() - 1); } else if (e.getSource() == plusGreenButton) { greenScrollbar.setValue(greenScrollbar.getValue() + 1); } else if (e.getSource() == minusGreenButton) { greenScrollbar.setValue(greenScrollbar.getValue() - 1); } else if (e.getSource() == plusBlueButton) { blueScrollbar.setValue(blueScrollbar.getValue() + 1); } else if (e.getSource() == minusBlueButton) { blueScrollbar.setValue(blueScrollbar.getValue() - 1); } } public static void main(String[] args) { new ColorPalette(); } } ```
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值