Hi all,
I have data frame to visualize with ggplot2 and geom_rect function, this is the data with command I used
a.d = read.table(text="Taxa Time Treatment Value
ASV23 T6 Ph1 0.049406532
ASV38 T6 Ph1 0.052542339
ASV125 T6 Ph1 0.092199603
ASV193 T6 Ph1 0.010195662
ASV219 T6 Ph1 0.09468832
ASV23 T12 Ph1 0.031924423
ASV38 T12 Ph1 0.18665094
ASV125 T12 Ph1 0.12314535
ASV193 T12 Ph1 0.031932642
ASV219 T12 Ph1 0.60457291
ASV23 T24 Ph1 0.049734573
ASV38 T24 Ph1 0.205076045
ASV125 T24 Ph1 0.162962756
ASV193 T24 Ph1 0.00786734
ASV219 T24 Ph1 0.16383689
ASV23 T48A Ph1 0.049406532
ASV38 T48A Ph1 0.052542339
ASV125 T48A Ph1 0.092199603
ASV193 T48A Ph1 0.010195662
ASV219 T48A Ph1 0.09468832
ASV23 T48B Ph2 0.049406532
ASV38 T48B Ph2 0.052542339
ASV125 T48B Ph2 0.092199603
ASV193 T48B Ph2 0.010195662
ASV219 T48B Ph2 0.09468832
ASV23 T66 Ph2 0.031924423
ASV38 T66 Ph2 0.18665094
ASV125 T66 Ph2 0.12314535
ASV193 T66 Ph2 0.031932642
ASV219 T66 Ph2 0.40457291
ASV23 T96A Ph2 0.049734573
ASV38 T96A Ph2 0.205076045
ASV125 T96A Ph2 0.162962756
ASV193 T96A Ph2 0.00786734
ASV219 T96A Ph2 0.16383689
ASV23 T96B Ph3 0.049734573
ASV38 T96B Ph3 0.205076045
ASV125 T96B Ph3 0.162962756
ASV193 T96B Ph3 0.00786734
ASV219 T96B Ph3 0.16383689
ASV23 T108 Ph3 0.049406532
ASV38 T108 Ph3 0.052542339
ASV125 T108 Ph3 0.092199603
ASV193 T108 Ph3 0.010195662
ASV219 T108 Ph3 0.09468832
ASV23 T120 Ph3 0.031924423
ASV38 T120 Ph3 0.18665094
ASV125 T120 Ph3 0.12314535
ASV193 T120 Ph3 0.031932642
ASV219 T120 Ph3 0.20457291
ASV23 T144 Ph3 0.049734573
ASV38 T144 Ph3 0.205076045
ASV125 T144 Ph3 0.162962756
ASV193 T144 Ph3 0.00786734
ASV219 T144 Ph3 0.16383689",
header=TRUE)
####
(a.d %>%
arrange(Treatment, Value) %>%
group_by(Treatment) %>%
mutate(
Xmin = min(Time),
Xmax = max(Time)
) %>%
ungroup() %>%
mutate(Treatment = as.factor(Treatment)) -> dt_for_plot)
minrate <- min(dt_for_plot$Value)
maxrate <- max(dt_for_plot$Value)
(rect_data <- dt_for_plot %>% select(Treatment, Xmin, Xmax) %>% distinct())
(alt_rect_data <- mutate(rect_data,
Xmax3=lead(Xmin),
Xmax=if_else(is.na(Xmax3),Xmax,Xmax3)))
ggplot(a.d) +
geom_rect(
data = alt_rect_data,
mapping = aes(
xmin = Xmin,
xmax = Xmax,
ymin = minrate,
ymax = maxrate,
fill = Treatment,
ymin=0, ymax=5, alpha=0.2)) +
geom_line(aes(x = Time, y = Value,
group = Taxa, color = Taxa,
linetype = Taxa),
size = 0.8) +
geom_point(aes(y= Value, x=Time, shape = Taxa),
color="navy", size=1.5) +
scale_shape_manual(values = c(16, 14, 22, 17, 15, 23)) +
scale_fill_brewer("Taxa", palette = "Blues") +
theme_classic() + scale_x_discrete(limits = c("T6", "T12", "T24", "T48A", "T48B", "T66", "T96A", "T96B", "T108", "T120", "T144"))
this was the output
my question is how to make the color start from time6 not form 12 and at the end to be till T144?
thanking your help