Solved: I want to color my bars in the plot by which group they are in.
Also: If possible, I would also like to have the colors gradient/fading by the value on the y axis, devided into intervalls of for example [-inf,0], [0,3], [3,10], [10, inf]
My data contains one column with the stop number (which I want to group by), one column with times (positive and negative relative to a time table) and trip ids.
structure(list(stop_sequence = c(1L, 13L, 18L, 6L, 1L, 13L, 18L,
6L, 1L, 13L, 18L, 6L, 1L, 13L, 18L, 6L, 13L, 18L, 1L, 13L, 18L,
6L), on_time = c(5, 231, 84, 126, 54, 274, 132, 159, 17, 7, 0,
6, -4, -20, 0, 28, 110, 0, 17, 199, 177, 197), trip_id = c(55700000048910944,
55700000048910944, 55700000048910944, 55700000048910944, 55700000048910968,
55700000048910968, 55700000048910968, 55700000048910968, 55700000048910992,
55700000048910992, 55700000048910992, 55700000048910992, 55700000048911024,
55700000048911024, 55700000048911024, 55700000048911024, 55700000048911176,
55700000048911176, 55700000048911256, 55700000048911256, 55700000048911256,
55700000048911256)), class = "data.frame", row.names = c(289L,
290L, 291L, 292L, 293L, 294L, 295L, 296L, 297L, 298L, 299L, 300L,
301L, 302L, 303L, 304L, 326L, 327L, 337L, 338L, 339L, 340L))
I have tried several thing, for example this below, but it gives me the error "Error: Continuous value supplied to discrete scale"
ggplot(data = tb_dir1, aes(x=stop_sequence, y=on_time, group = stop_sequence, fill=trip_id), names.arg = tb_dir1$stop_sequence) +
geom_bar(stat="identity", position = "dodge2", width = 5) +
scale_fill_manual(palette="Drak2")+
geom_text(aes(label=on_time), color="black",
position = position_dodge2(5),vjust = -.25, size=2)+
scale_x_discrete(name = "Stop sequence",
limits=x_labels)+
theme_minimal()
With this code (without the scale_fill_manual)
ggplot(data = tb_dir1, aes(x=stop_sequence, y=on_time, group = stop_sequence, fill=trip_id), names.arg = tb_dir1$stop_sequence) +
geom_bar(stat="identity", position = "dodge2", width = 5) +
geom_text(aes(label=on_time), color="black",
position = position_dodge2(5),vjust = -.25, size=2)+
scale_x_discrete(name = "Stop sequence",
limits=x_labels)+
theme_minimal()