library(ggplot2)
library(dplyr)
df <- data.frame(dose = c("D0.5", "D1", "D2", "D3", "D4", "D5"),
len = c(4.2, 10, 29.5, 5, 7, 15))
df <- df |>
dplyr::arrange(desc(len)) |>
dplyr::mutate(
rank = factor(row_number(), labels = dose)
)
fill_colors = c("blue", "yellow", "green")
other_colors = rep("grey50", nrow(df)-length(fill_colors))
my_scale <- c(fill_colors, other_colors)
withr::with_options(
list(ggplot2.discrete.fill = my_scale),
ggplot(data = df, aes(x = reorder(dose, len), y = len))
geom_bar(stat = "identity", aes(fill = rank), width = 0.5)
scale_fill_discrete() theme_minimal()
xlab("len") ylab("type")
coord_flip()
)
CodePudding user response:
Maybe a slightly different look works too, with geom_text on top of the bars?