0

Take the following data

df <- data.frame(ID = c(1, 1, 2, 2, 3, 3),
                 cond = c(2, 2, 2, 2, 2, 2),
                 Time = c(1,2,1,2,1,2),
                 State  = c("Empty", "Empty", "Empty", "Full", "Full", "Empty"),
                 eye = c(2, -3, -2, 1, 0, -2),
                 combination = c(1, 1,2, 2, 3, 3))

and the plot

ggplot(df, aes(x = Time, y = eye)) +
  geom_point(aes(shape=State), size = 3.5) +
  scale_shape_manual(values=c(13,15)) +  
  geom_line(aes(group=ID, color = Time, alpha = State), size = 5) +
    
  theme(legend.title=element_blank(),
        axis.title.x=element_text(size = 12),
        axis.title.y=element_text(size = 12),
        plot.title = element_text(hjust = 0.5, size = 15),
        axis.text.x= element_text(color = "black"),
        axis.text.y= element_text(color = "black"),
        axis.line = element_line(colour = "black"),
        plot.background = element_rect(fill = "white"),
        panel.background = element_rect(fill = "white"))

which produces

enter image description here

my problem is

  1. this gives the lines different alphas, but I want the lines to have gradient alpha. Specifically, I need the line that goes between 'empty' and 'full' state to start with low alpha and end with high alpha, and the line that goes from 'full' to 'empty' to start with high alpha and end with low alpha. (the line that goes from 'low' to 'low' is okay as it is in the example).

  2. On the x-axis, instead of starting at x = 1 and ending at x = 2, I want the 'empty' to 'full' line to start at 1.25 and then 'fade in' to end at 2, and I want the 'full' to 'empty' line to start at 1.00 and 'fade out' to end at 1.75.

I have been hassling with this problem for a while now, any help is much appreciated.

Icewaffle
  • 443
  • 2
  • 13
  • 2
    I think the main way I've seen to do this in the past is to interpolate more data between your two end points and then make the gradient based on those values. You can see an example [in this answer](https://stackoverflow.com/a/17794763/2461552), for example. – aosmith Jun 24 '21 at 23:07
  • Yeah I told him that the last time he asked the same question. – Baraliuh Jun 25 '21 at 00:16
  • See answer to https://stackoverflow.com/questions/68068302/r-scale-alpha-not-continuous/68124048#68124048... This seems like duplicate question. – Jon Spring Jun 25 '21 at 02:05
  • An answer to this problem can be found here: https://stackoverflow.com/questions/68068302/r-scale-alpha-not-continuous/68124048#68124048 – Icewaffle Jun 25 '21 at 02:57

0 Answers0