Passing a column name to fill in as a string with ggvis

ggvis will automatically color my plot based on the column of factors through which I pass it. So if my factor column was called "area", I could write this and it will work just fine.

names = c("Bacilli", "Actinobacteria", "area")
b_counts <- c(1,5,8,100,34,3)
a_counts <- c(1,3,11,55,67,11)
area <- c("Gut", "Skin", "Gut", "Gut", "Skin", "Oral")
rel_data <- data.frame(b_counts, a_counts, area)
names(rel_data) <- names

library(ggvis)
library(dplyr)

rel_data %>% ggvis(x = input_select(names(rel_data[,-3]), map = as.name, label = "X Axis"), 
               y = input_select(names(rel_data[,-3]), map = as.name, label = "Y Axis")) %>%
  filter(area %in% eval(input_checkboxgroup(unique(rel_data$area), selected = "Gut"))) %>%
  layer_points(fill = ~area) ### section of interest

However, if I want to pass the column name as a string, I cannot get it to work. eg.

region <- "area"
layer_points(fill = ~region)

I tried as.name, eval, quote, etc., but I can't get anything to work. Does anyone have any ideas?

+4
source share
1 answer

There is a hint about the properties and scales :

layer_points(prop("fill", as.name(region)))
+3
source

All Articles