R-散点图的颜色键 [英] R - color key for a scatterplot

查看:54
本文介绍了R-散点图的颜色键的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在R中工作,正在创建一个3变量散点图,其中x和y对应于位置,颜色由z给出.

I'm working in R and am creating a 3-variable scatter plot, with x and y corresponding to position, and color given by z.

但是,由于我的项目的特殊性,我无法使用现有的调色板,而是编写了一个直接将数据转换为 rgb 值的函数.

However, due to the specifics of my project, I couldn't use an existing color palette, and instead wrote a function directly converting data into rgb values.

我能够使图形看起来像我想要的样子(颜色正确),但是我不知道如何创建合适的颜色键.

I'm able to get the graph to look the way I want (the colors are correct), but I don't know how to create a suitable color key.

假设我已经完成了所有想做的处理,现在有一个数据结构,其中第1列是x值,第2列是y值,第3列是我想成为颜色的rgb值点,第4列是用于生成给定点的颜色十六进制值的分数,我如何最好地将其显示为带有颜色键的散点图?

Assuming I've already done all the processing I want to do, and now have a data structure where column 1 is the x value, column 2 is the y value, column 3 is the rgb value I want to be the color of the point, and column 4 is the score used to generate the color hex value of a given point, how would I best display this as a scatter plot with color key?

我希望键覆盖整个颜色范围,并从0到最高分.

I want the key to cover the entire color range and go from 0 to the max score.

得分(第4列)不需要在图表中-它们仅用于分配颜色十六进制值,并确定颜色键的范围.

The scores (column 4) don't need to be in the graph - they are just used to assign the color hex values, and to determine the range of the color key.

推荐答案

下面是一个简单的示例,说明如何使用spatstat和plotrix处理调色板和地图:

Here is a simple example of how to work with colour palettes and maps using spatstat and plotrix:

library("spatstat") ; library("plotrix")

#your data:
x <- 1:3
# the colours included
colors <- c("#FF0000" , "#00FF00" , "#0000FF")
n.colors <- 100 # number of colours to interpolate over

plot(1:3 , col = colors , pch = 16)

# interpolate colours:
palette <- colorRampPalette(colors, space = "rgb")(n.colors)
color.map <- colourmap( palette , range=range(x) )
color.range <- color.map( seq(min(x), max(x), length.out = n.colors) )

#the labels of the legend
col.labels <- round(seq(min(x),max(x),length=3) ,digits=1)
color.legend( xl =2.5 , yb = 1, xr = 2.7, yt = 2 , # the coordinates
              legend = col.labels , gradient="y", 
              rect.col=color.range, align="rb")

这篇关于R-散点图的颜色键的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆