【发布时间】:2014-12-21 16:22:51
【问题描述】:
这与this question 有关,但可能是一个更简单的例子。我很好奇是否有一种合理的方法来计算给定三种或四种任意颜色的多维颜色渐变,就像 r rgb() 函数对红色、绿色、蓝色所做的那样?一维梯度很容易(图 1),但我不清楚如何计算二维梯度(图 2)三角形内。边缘很容易。重要的是里面的东西
# one dimensional color gradient
one.dimensions <- colorRampPalette( c( "orange" , "blue" ) )( 100 )
plot( 1:100 , rep( 1 , 100 ) , col = one.dimensions , cex = 3 , pch = 16 , main = 'one dimensional gradient' )
# here are the edges of a three-colored triangle
dimensions13 <- colorRampPalette( c( "orange" , "blue" ) )( 100 )
dimensions12 <- colorRampPalette( c( "orange" , "red" ) )( 100 )
dimensions23 <- colorRampPalette( c( "blue" , "red" ) )( 100 )
plot( 1:100 , c( 1:50 , 50:1 ) , type = 'n' , main = 'two dimensional gradient' )
points( 1:100 , rep( 1 , 100 ) , col = dimensions12 , cex = 3 , pch = 16 )
points( seq( 1 , 50 , length = 100 ) , seq( 1 , 50 , length = 100 ) , col = dimensions13 , cex = 3 , pch = 16 )
points( seq( 50 , 100 , length = 100 ) , seq( 50 , 1 , length = 100 ) , col = dimensions23 , cex = 3 , pch = 16 )
【问题讨论】:
-
也许this Q&A 有帮助?
-
附注:当您写二维和三维时,您是指一维和二维(例如 x 维与 x 和 y 维)吗?
-
@Henrik duh 好点 :)
-
没问题!也许还可以更改情节标题;)
-
@Henrik 问答非常相关,但我确实想要渐变中心的那些白色 X,看起来回答者都没有提供如何做到这一点? ://
标签: r graphics colors ggplot2 palette