首页 > 解决方案 > R:基于不是一列而是两列的值的颜色标记

问题描述

假设我有一个名为的文件complete.LINA.Fourier.table,我将其读入数据框中。这是它的样子,这是链接

"Model_ID" "Z" "X" "M" "L" "T" "non-linear period" "log(P)" "skewness" "acuteness" "mean mag" "err in mean mag" "A1" "A1_err" "phi1" "phi1_err" "R21" "R21_err" "R31" "R31_err" "P21" "P21_err" "P31" "P31_err" "FU_Lin_Period" "FU_Growth_rate" "FO_Lin_Period" "FO_Growth_rate"
1 0.00038 0.75053 0.5 35 6000 0.75346 -0.123 -0.306 Inf 1.043 0 0.01 0 0.653 0 0.091 0 0.009 0 3.097 0 0.137 0.002 NA NA NA NA
2 0.00038 0.75053 0.5 35 6050 0.72079 -0.142 -0.17 Inf 1.035 0 0.064 0 0.538 0 0.56 0 0.289 0 3.168 0 6.182 0 0.72127 0.0093333 NA NA
3 0.00038 0.75053 0.5 35 6100 0.69229 -0.16 -0.143 Inf 1.027 0 0.086 0 0.401 0 0.631 0 0.4 0 3.348 0 0.13 0 0.69281 0.015857 NA NA
4 0.00038 0.75053 0.5 35 6150 0.66689 -0.176 -0.117 Inf 1.02 0 0.107 0 0.249 0 0.592 0 0.435 0 3.526 0 0.402 0.001 0.66735 0.021103 NA NA
5 0.00038 0.75053 0.5 35 6200 0.64382 -0.191 -0.11 Inf 1.014 0 0.133 0 0.091 0 0.514 0 0.425 0 3.644 0.001 0.598 0.001 0.64414 0.024205 NA NA

7247 0.00061 0.74996 0.8 105 6800 0.61635 -0.21 -0.331 Inf -0.276 0 0.264 0 0.243 0 0.064 0 0.063 0 1.5 0.001 1.71 0.001 0.83493 0.0012547 0.61602 0.01916

R21我计划制作一个vs的散点图log(P)。我想根据列FU_Lin_PeriodFO_Lin_Period以下条件为标记着色。

If (FU = NA and FO = NA) or (FU < 0 and FO < 0), do not plot the marker
If  FU > 0 and ( FO < 0 or FO = NA ), color the marker blue
If  FO > 0 and ( FU < 0 or FU = NA ), color the marker red
If FU > 0 and FO > 0, color the marker with a purple gradient, closer to red if FO > FU and closer to FU if FU > FO.

这是我现在正在尝试测试颜色的内容。

complete.LINA.Fourier.table$colour="black"
complete.LINA.Fourier.table$colour[complete.LINA.Fourier.table$FU_Growth_rate > 0 & complete.LINA.Fourier.table$FO_Growth_rate < 0]="blue"
complete.LINA.Fourier.table$colour[complete.LINA.Fourier.table$FU_Growth_rate < 0 & complete.LINA.Fourier.table$FO_Growth_rate > 0]="red"

png(file.path("R21_vs_logP_V_band.png"), width = 750, height = 600)
par(mar=c(5,5,4,1)+.1)
plot(complete.LINA.Fourier.table$`log(P)`, complete.LINA.Fourier.table$R21, xlab=expression("log(P)"), ylab=expression(R['21']), col=complete.LINA.Fourier.table$colour, pch=3, cex=0.8, cex.lab=1.25, ceb.axis=3.0)
dev.off()

然而,到目前为止,我的代码将所有标记都绘制为黑色。

我想知道是否有人可以指出我的方向或帮助我弄清楚我错过了什么。这将不胜感激。

标签: r

解决方案


推荐阅读