I have a question about controlling the color of datapoints in ggvis.
I have a dataframe that I am filtering in multiple ways (within a shiny app in case it matters).
It seems as if I overlooked a very easy solution:
Just re-define the levels of the factor, and drop the factor from the fill=
I'll leave this up as it might help someone else.
dfvis$mygroup<-factor(dfvis$mygroup, levels=c("A", "B", "C", "D", "E"))
dfvis %>%
ggvis(x= ~x, y= ~y) %>%
layer_points(fill = ~mygroup)
This may actually have more generalizability for ggvis users. We can take advantage of : versus :=. Make a new variable of colors for each group
dfvis$color <- c("blue","orange","green","red","purple")
Then we can use the unscaled raw value of colors with fill:= inside the ggvis function...
#:= denotes unscaled raw value
dfvis %>%
ggvis(x= ~x, y= ~y, fill:= ~color) %>%
layer_points()
This will ensure color consistency even after filtering out other groups.