I have plotly
graphics where I'd like to change axis tick mark labels to specific strings. Consider the following example:
library(plotly)
p <- plot_ly(data = iris, x = ~Sepal.Length, y = ~Petal.Length)
Say I want to supress all numeric xaxis tick mark labels and instead only plot the string "min" at x = 4.5
and "max" at x = 8
.
How can I achieve this in plotly
?
Sidenote: I know this is possible for base R plots, e.g. here and in ggplot2
by setting scale_x_continuous(breaks = c(4.5, 8), labels= c("4.5" = "min", "8" = "max"))
.
Is there also a way to achieve this in plotly
?
..Unfortunately the plotly
docs don't seem to offer a solution..
Thanks to @eipi10 and @Jon Spring I could figure it out:
library(plotly)
plot_ly(data = iris, x = ~Sepal.Length, y = ~Petal.Length) %>%
layout(xaxis = list(tickvals = c(4.5, 8), ticktext = c("min", "max")))
This is exactly what I was searching for and produces:
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With