How can I make curves with a color gradient in R. Take a look at this flame.
如何在R中制作带有颜色渐变的曲线。看看这个火焰。
It should look like that. I tried to make a normal curve and then another normal curve, but technically speaking, you can't make such a figure with a bunch of normal curves because they won't come down and intersect at the right spot on either side. How can I make such a figure in R? Any ideas?
看起来应该是这样的。我尝试制作一条正常曲线,然后是另一条正常曲线,但从技术上讲,你不能用一堆正常曲线制作这样一个数字,因为它们不会在两侧的正确位置下降并相交。我如何在R中制作这样的数字?有任何想法吗?
1 个解决方案
#1
24
The best I've been able to do so far is:
到目前为止我能做的最好的是:
par(bg="black")
plot(seq(0.15,0.85,by=0.01),
5*dbeta(seq(0.15,0.85,by=0.01),10,10 ),
type="l" , ylim=c(0,700) ) # this just sets up the plotting framework.
for( i in 1:200 ) { lines(x= seq(0.15,0.85,by=0.01),
y= i*dbeta(seq(0.15,0.85,by=0.01),10,10 ),
col= colorRampPalette(c("yellow", "orange", "red", "hotpink",
"violet", "blue", "lightblue", "lightgreen", "darkgreen",
"black"))(200)[i],
lwd=13) }
par(bg="white")
I did discover that putting a "black" color at the beginning of that series add an extra "glow" to the overall result, but I'm not posting that result.
我确实发现在该系列的开头添加“黑色”颜色会为整体结果添加额外的“发光”,但我不会发布该结果。
-----------------
This is what I started with and then there are successive approximation and tweaks appearing below:
这是我开始的,然后有下面出现的连续近似和调整:
plot(seq(0.15,0.85,by=0.01), 5*dbeta(seq(0.15,0.85,by=0.01),10,10 ),
type="l" , ylim=c(0,100))
for( i in seq(0.2, 5) ) { lines(seq(0.15,0.85,by=0.01),
i*5*dbeta(seq(0.15,0.85,by=0.01),10,10 ) ) }
For colors:
对于颜色:
plot(seq(0.15,0.85,by=0.01), 5*dbeta(seq(0.15,0.85,by=0.01),10,10 ), type="l" ,
ylim=c(0,130))
for( i in 1:35 ) {lines(seq(0.15,0.85,by=0.01), i*dbeta(seq(0.15,0.85,by=0.01), 10,10 ),
col=colorRampPalette(c("yellow", "orange", "red", "violet",
"blue", "lightblue", "lightgreen"))(35)[i],
lwd=3) }
For black background and denser colors and a fade to black at top:
对于黑色背景和更密集的颜色以及在顶部淡化为黑色:
par(bg = 'black')
plot(seq(0.15,0.85,by=0.01), 5*dbeta(seq(0.15,0.85,by=0.01),10,10 ), type="l",
ylim=c(0,130) )
for( i in 1:35 ) { lines(seq(0.15,0.85,by=0.01), i*dbeta(seq(0.15,0.85,by=0.01),10,10),
col=colorRampPalette(c("yellow", "orange", "red", "violet",
"blue", "lightblue", "lightgreen", "darkgreen",
"black")) (35)[i],
lwd=13) }
I noticed that the fading to black aspect also controlled the line width at the sides. I hadn't been expecting that but it seems to be a desirable feature. The other aspect not addressed here is the possibility of adding transparency. There is an alpha argument in the R RGB functions.
我注意到黑色方面的褪色也控制了两侧的线宽。我没有想到这一点,但它似乎是一个理想的功能。这里没有提到的另一个方面是增加透明度的可能性。 R RGB函数中有一个alpha参数。
One useful trick for finding colors byname:
查找颜色byname的一个有用技巧:
grep("purple", colors(), value=TRUE)
[1] "mediumpurple" "mediumpurple1" "mediumpurple2" "mediumpurple3" "mediumpurple4"
[6] "purple" "purple1" "purple2" "purple3" "purple4"
If you are playing with the iteration to make the gradient smoother then you will need also adjust the ylim argument: choose 0.5^9*0.5^9/beta(10,10)*[iterations] , since that will be the maximum at x=0.5.
如果你正在玩迭代以使渐变更平滑,那么你还需要调整ylim参数:选择0.5 ^ 9 * 0.5 ^ 9 / beta(10,10)* [迭代],因为这将是x的最大值= 0.5。
#1
24
The best I've been able to do so far is:
到目前为止我能做的最好的是:
par(bg="black")
plot(seq(0.15,0.85,by=0.01),
5*dbeta(seq(0.15,0.85,by=0.01),10,10 ),
type="l" , ylim=c(0,700) ) # this just sets up the plotting framework.
for( i in 1:200 ) { lines(x= seq(0.15,0.85,by=0.01),
y= i*dbeta(seq(0.15,0.85,by=0.01),10,10 ),
col= colorRampPalette(c("yellow", "orange", "red", "hotpink",
"violet", "blue", "lightblue", "lightgreen", "darkgreen",
"black"))(200)[i],
lwd=13) }
par(bg="white")
I did discover that putting a "black" color at the beginning of that series add an extra "glow" to the overall result, but I'm not posting that result.
我确实发现在该系列的开头添加“黑色”颜色会为整体结果添加额外的“发光”,但我不会发布该结果。
-----------------
This is what I started with and then there are successive approximation and tweaks appearing below:
这是我开始的,然后有下面出现的连续近似和调整:
plot(seq(0.15,0.85,by=0.01), 5*dbeta(seq(0.15,0.85,by=0.01),10,10 ),
type="l" , ylim=c(0,100))
for( i in seq(0.2, 5) ) { lines(seq(0.15,0.85,by=0.01),
i*5*dbeta(seq(0.15,0.85,by=0.01),10,10 ) ) }
For colors:
对于颜色:
plot(seq(0.15,0.85,by=0.01), 5*dbeta(seq(0.15,0.85,by=0.01),10,10 ), type="l" ,
ylim=c(0,130))
for( i in 1:35 ) {lines(seq(0.15,0.85,by=0.01), i*dbeta(seq(0.15,0.85,by=0.01), 10,10 ),
col=colorRampPalette(c("yellow", "orange", "red", "violet",
"blue", "lightblue", "lightgreen"))(35)[i],
lwd=3) }
For black background and denser colors and a fade to black at top:
对于黑色背景和更密集的颜色以及在顶部淡化为黑色:
par(bg = 'black')
plot(seq(0.15,0.85,by=0.01), 5*dbeta(seq(0.15,0.85,by=0.01),10,10 ), type="l",
ylim=c(0,130) )
for( i in 1:35 ) { lines(seq(0.15,0.85,by=0.01), i*dbeta(seq(0.15,0.85,by=0.01),10,10),
col=colorRampPalette(c("yellow", "orange", "red", "violet",
"blue", "lightblue", "lightgreen", "darkgreen",
"black")) (35)[i],
lwd=13) }
I noticed that the fading to black aspect also controlled the line width at the sides. I hadn't been expecting that but it seems to be a desirable feature. The other aspect not addressed here is the possibility of adding transparency. There is an alpha argument in the R RGB functions.
我注意到黑色方面的褪色也控制了两侧的线宽。我没有想到这一点,但它似乎是一个理想的功能。这里没有提到的另一个方面是增加透明度的可能性。 R RGB函数中有一个alpha参数。
One useful trick for finding colors byname:
查找颜色byname的一个有用技巧:
grep("purple", colors(), value=TRUE)
[1] "mediumpurple" "mediumpurple1" "mediumpurple2" "mediumpurple3" "mediumpurple4"
[6] "purple" "purple1" "purple2" "purple3" "purple4"
If you are playing with the iteration to make the gradient smoother then you will need also adjust the ylim argument: choose 0.5^9*0.5^9/beta(10,10)*[iterations] , since that will be the maximum at x=0.5.
如果你正在玩迭代以使渐变更平滑,那么你还需要调整ylim参数:选择0.5 ^ 9 * 0.5 ^ 9 / beta(10,10)* [迭代],因为这将是x的最大值= 0.5。