I am creating a list of ggplots to make an animation. I want to select a shortcut along the x axis, and the position of this selection changes over different frames of the animation.
Here is an example plot. The first axis mark should be highlighted in the first frame, and the second in the second frame.
p <- ggplot(mtcars, aes(factor(cyl), mpg)) + geom_boxplot() p_list <- list() for(i in 1:2) { x_label_cols <- rep("grey50", 3) x_label_cols[i] <- "red" p_list[[i]] <- p + opts( axis.text.x = theme_text( colour = x_label_cols ) ) }
Unfortunately, it seems that x_label_cols is evaluated when the chart is printed, and not when it is created, so both frames highlight the second label. Therefore, print(p_list[[1]]) not display correctly.
How do I get different colors of axis labels for each graph in the list?
source share