-
Notifications
You must be signed in to change notification settings - Fork 631
Closed
Description
On a horizontal barplot, trying to shorten y-tick labels using <br>
line breaks leaves too much room for the label.
Here's an example of a long label (no line breaks):
library(plotly)
long_label = "Dinner (or, super long label to check out some line breaks in plotly)"
dat1 <- data.frame(
sex = factor(c("Female","Female","Male","Male")),
time = factor(c("Lunch",long_label,"Lunch",long_label), levels=c("Lunch",long_label)),
total_bill = c(13.53, 16.81, 16.24, 17.42)
)
p <- ggplot(data=dat1, aes(x=time, y=total_bill, fill=sex)) +
geom_bar(stat="identity", position=position_dodge()) +
coord_flip() + theme_bw()
p <- ggplotly(p)
ggplotly(p)
After adding line breaks in the labels, the plot stays squished to the right:
library(plotly)
long_label = "Dinner (or, super long label<br>to check out some<br>line breaks in plotly)"
dat1 <- data.frame(
sex = factor(c("Female","Female","Male","Male")),
time = factor(c("Lunch",long_label,"Lunch",long_label), levels=c("Lunch",long_label)),
total_bill = c(13.53, 16.81, 16.24, 17.42)
)
p <- ggplot(data=dat1, aes(x=time, y=total_bill, fill=sex)) +
geom_bar(stat="identity", position=position_dodge()) +
coord_flip() + theme_bw()
p <- ggplotly(p)
ggplotly(p)
When it should look more like this (but with the rest of the label):
I think the issue might have something to do with the way that 'nchar' in the ggplotly function is counting characters of each tick label, without splitting by <br>
first.
Thanks for looking into this!
Metadata
Metadata
Assignees
Labels
No labels