Ggplot2 + plotly: axis name disappears

I have a problem when using the ggplotly() graph for ggplot : the y axis disappears. Here's a reproducible example using the iris dataset (this example is quite a dump, but whatever)

 data(iris) g = ggplot(data = iris, aes(x = Petal.Length, y = Petal.Width, fill = Species)) + geom_bar(stat = "identity", position = "dodge") + scale_fill_manual(name = "legend", values = c("blue", "red", "green")) + ylab("Y title") + ylim(c(0,3)) + xlab("X title") + ggtitle("Main title") g ggplotly(g) 

As you can see, the name of the Y axis has disappeared.

Well, if ylim removed, it works, but I would like to specify y limits.

I tried to do the following:

 data(iris) g = ggplot(data = iris, aes(x = Petal.Length, y = Petal.Width, fill = Species)) + geom_bar(stat = "identity", position = "dodge") + scale_fill_manual(name = "legend", values = c("blue", "red", "green")) + scale_y_continuous(name = "Y title", limits = c(0, 3)) + xlab("X title") + ggtitle("Main title") g ggplotly(g) 

But now this is the name of a legend that does not fit.

My configuration: R 3.2.0, plotly 2.0.16, ggplot2 2.0.0

In both examples, the graph given by ggplot is what I want, but ggplotly gives something else. This is a problem, is there a workaround?

+6
source share
2 answers

I'm not sure why this is happening, but there is work to do. This will give you what you want.

 p <- ggplotly(g) x <- list( title = "X Title" ) y <- list( title = "Y Title" ) p %>% layout(xaxis = x, yaxis = y) 
+7
source

I had a similar problem. The ggplot object pushed through ggplotly showed off clipping my y-axis label [in a Shiny app].

To fix this, I did what MLavoie suggested, but then he had BOTH my ggplot tags and my shortcuts. To fix this, I just set the ggplot labels to spaces, and it worked (if you didn't set anything, the plotly labels will overlap with the axis label labels).

 p <- ggplotly(g + ylab(" ") + xlab(" ")) x <- list( title = "X Title" ) y <- list( title = "Y Title" ) p %>% layout(xaxis = x, yaxis = y) 
+2
source

All Articles