Reputation: 11762
I have a problem with ggplotly
command.
It erases the xlab
or ylab
text if I scale the axis with scale_x_continuous
.
library(plotly)
df <- data.frame(a=letters, b=LETTERS, x=runif(26), y=runif(26))
g <- ggplot(df, aes(x,y)) +
geom_point(aes(text=sprintf('letter: %s\nLetter: %s', a, b))) +
xlab('test') + ylab('test') +
scale_x_continuous(breaks=seq(-100,100,.1), minor_breaks=seq(-100,100,.05), limits=c(0,1))
g
(gg <- ggplotly(g))
The g
graph is still fine with both labels on the axis but the ggplotly
graph deletes the title if I set a scale
to any of the axis.
This is independent of the axis. But I didn't checked other scales
so far.
Any idea why this happens and how to solve it?
Upvotes: 2
Views: 464
Reputation: 98419
Im not sure that it is intended but if you use scale_...
function then you have to provide axis title inside scale_...
because title set inside labs()
or xlab()
/ylab()
is ignored.
g <- ggplot(df, aes(x,y)) +
geom_point(aes(text=sprintf('letter: %s\nLetter: %s', a, b))) +
ylab('test') +
scale_x_continuous("test",breaks=seq(-100,100,.1),
minor_breaks=seq(-100,100,.05), limits=c(0,1))
g
(gg <- ggplotly(g))
Upvotes: 2