I have some code here that will use colorRampPalette() and scale_color_gradientn() to color the points along the scale of the limits.
Colors <- colorRampPalette(c("beige", "darkolivegreen1","green","aquamarine", "darkcyan",
"dodgerblue4", "purple4", "magenta3", "pink"))
Colors_range <- Colors(50)
ggplot(iris, aes(x = Petal.Width, y = Petal.Length, color = Petal.Length)) +
geom_point() +
facet_wrap(~ Species, scales = "free_y") +
scale_color_gradientn(colors = Colors_range, limits = c(0,7))
I want there to be a way to adapt this to continuously color the y or x axes rather than the points. I can do one solid color with axis.line.y
ggplot(iris, aes(x = Petal.Width, y = Petal.Length)) +
geom_point() +
facet_wrap(~ Species, scales = "free_y") +
theme(axis.line.y = element_line(size = 3, color = "green", linetype=1))
I see a potential way to use geom_vline somehow but prefer axis.line.y in the respect that it doesn't shift the plot at all.
ggplot(iris, aes(x = Petal.Width, y = Petal.Length)) +
geom_point() +
facet_wrap(~ Species, scales = "free_y") +
geom_vline(xintercept = -0.1, color = "green", size = 3)
Not aware of an option to get a gradient colored axis line. Instead, if you want to fake an axis line then one option would be to use
ggforce::geom_link2where I set the limits viacoord_cartesian:A second option would be to use a
geom_linewhich however requires some additional data wrangling: