plotly - ggplotly - R, labeling trace names -
i'm new plotly , not able find relevant documentation on how name traces meaningful label appears in plot rendered ggplotly
. here ggplotly site shows number of examples. needed show meaningful label on hover instead of value followed trace0, trace1, etc.
for example, in first plot, how can labels appear shows:
proportion: value
total bill: value
ideally, directly in r rather through web interface. in advance.
you can edit of plotly figure properties after ggplot2 conversion before send plotly. here example changes legend entry names manually. i'll repeat here:
df <- data.frame(x=c(1, 2, 3, 4), y=c(1, 5, 3, 5), group=c('a', 'a', 'b', 'b')) g <- ggplot(data=df, aes(x=x, y=y, colour=group)) + geom_point() # intermediate step `ggplotly` calls p <- plotly_build(g) # manually change legend entry names, "trace0", "trace1" in case p$data[[1]]$name <- 'group a' p$data[[2]]$name <- 'group b' # send plotly account p$filename <- 'ggplot2-user-guide/custom-ggplot2' plotly_post(p)
the extended example here explains in more detail how , why works.
note in general legend item names, e.g. "trace0", going labels grouped in dataframe (as in ggplot2).
Comments
Post a Comment