0

I am trying to interpolate a color palette based on the values of the variable "weight" of my dataset.

F2 <- colorRampPalette(c("#c2c6b3", "#353828"), bias = length(unique(E(gD)$weight)), space = "rgb", interpolate = "linear")

However, some values on my dataset have NA values, and this provoques a (0) value on the color generated for that edge on my network graph.

As a result, when I try to assign the colors generated from this function into the edges of my network graph in R,

colCodes <- F2(length(unique(E(gD)$weight2)))
edges_col <- sapply(E(gD)$weight2, function(x)
colCodes[which(sort(unique(E(gD)$weight2)) == x)])`
edges_col_df <- as.data.frame(t(col2rgb(edges_col, alpha = FALSE)))

I get the error: "invalide color name `character(0)'"

I saw on a different post how to extrapolate on the case of missing values by the median o mean of values around the missing observation Imputing missing values keeping circular trend in mind but in my case, I would like the observations with NA values to acquire the value of the lower limit of my range of colors.

Community
  • 1
  • 1
  • You should include a [reproducible example](http://stackoverflow.com/questions/5963269/how-to-make-a-great-r-reproducible-example) with sample input data so we can run your code to see what's going on. Describe precisely the desired result for the sample input you provide. – MrFlick Jul 21 '15 at 02:05

1 Answers1

1

One possible solution would be to recode the NA values to the corresponding lower limit value.

data$variable[is.na(data$variable)]<-min(data$variable)

Sometimes to make this vector a new variable for data integrity reasons.

data$variable2[is.na(data$variable)]<-min(data$variable)

Hope this helps!

Andrew Ferris
  • 123
  • 2
  • 11