data(canada.cities, package = “maps”)
viz <- ggplot(canada.cities, aes(long, lat)) +
borders(regions = “canada”) +
coord_equal() +
geom_point(aes(text = name, size = pop), colour = “red”, alpha = 1/2) +
ggtitle(paste(“Average bill for 1 people \n”,
“Average bill for 2 people \n”,
“Average bill for 3 people \n”,
“Average bill for 4 people”, sep = “”))
ggplotly(viz)
Hi, so what you could try to do is replace \n with <br>. However the issue will be that the title will start to conflict with your chart.
So in addition to that, you would have to edit the height of the top margin. You can do this with the following commands:
viz2 <- plotly_build(viz)
viz2$layout$margin$t = 100 #note you may have to change this number
# in addition you may also have to change the height and width of the plot
viz2$layout <- c(viz2$layout, list(height=1000, width=1000))
viz2
Thank you very much. It works. However, when I downloaded the plot produced by plotly, it has the same problem as before, i.e., the title is getting cut off. I appreciate your kind help.
data(canada.cities, package = “maps”)
viz <- ggplot(canada.cities, aes(long, lat)) +
borders(regions = “canada”) +
coord_equal() +
geom_point(aes(text = name, size = pop), colour = “red”, alpha = 1/2) +
ggtitle(paste(“Average bill for 1 people <br”,
“Average bill for 2 people <br”,
“Average bill for 3 people <br”,
“Average bill for 4 people”, sep = “”))
ggplotly(viz)
viz2 <- plotly_build(viz)
viz2$layout$margin$t = 150 #note you may have to change this number# in addition you may also have to change the height and width of the plot
viz2$layout <- c(viz2$layout, list(height= 600, width= 600))
viz2
I have removed “>” in “<br” for this post, otherwise it was adding new line.