0
votes

I am trying to use color to highlight differences between and within factor levels. For example, with these reproducible data:

set.seed(123)
dat <- data.frame(
  Factor = sample(c("AAA", "BBB", "CCC"), 50, replace = T),
  ColorValue = sample(1:4, 50 , replace = T),
  x = sample(1:50, 50, replace =T),
  y = sample(1:50, 50, replace =T))
head(dat)

  Factor ColorValue  x  y
1    AAA          1 30 43
2    CCC          2 17 25
3    BBB          4 25 20
4    CCC          1 48 13
5    CCC          3 25  6
6    AAA          1 45 20

I want to have a different color for each Factor. Then, within each factor I am trying to use ColorValue as a continuous coloring variable to show intensity.

In the plot below, each facet would have different shades of red, green, and blue that reflect the ColorValue, ideally with a single intensity (i.e. ColorValue) legend for all three factor levels.

 ggplot(dat, aes(x = x, y = y, color = Factor)) +
  geom_point(size = 3) +
  facet_wrap(~Factor) + 
  theme_bw()

enter image description here

1
Maybe alpha=ColorValue will do something similar - S Rivero
ggplot(dat, aes(x = x, y = y, color = Factor, alpha=ColorValue)) - CPak
@S Rivero post as answer...? - B. Davis

1 Answers

0
votes
 ggplot(dat, aes(x = x, y = y, color = Factor, alpha = ColorValue)) +
  geom_point(size = 3) +
  facet_wrap(~Factor) + 
  theme_bw()

Result