Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 5 additions & 5 deletions topics.Rmd
Original file line number Diff line number Diff line change
Expand Up @@ -204,7 +204,7 @@ library(scales)
p <- ggplot(txhousing, aes(date, median)) +
geom_line(aes(
group = city,
text = paste("median:", number_si(median))
text = paste("median:", label_number(scale_cut = cut_short_scale())(median)
))
ggplotly(p, tooltip = c("text", "x", "city"))
```
Expand All @@ -229,10 +229,10 @@ length(w$x$data)

# use the `y` attribute of the smooth line
# to generate a custom string (to appear in tooltip)
text_y <- number_si(
w$x$data[[2]]$y,
text_y <- label_number(
scale_cut = cut_short_scale(),
prefix = "Typical median house price: $"
)
)(w$x$data[[2]]$y)

# suppress the tooltip on the raw time series
# and supply custom text to the smooth line
Expand Down Expand Up @@ -1090,4 +1090,4 @@ ggplotly(p) %>% hide_legend()
knitr::include_graphics("images/xspline.svg")
```

In more complicated cases, where your custom geom cannot be converted to a lower level geom, a custom method for the `geom2trace()` generic is required (`methods(geom2trace)` lists all the basic geoms that we natively support). This method should involve a conversion from a data frame to a list-like object conforming to the [plotly.js figure reference](https://plot.ly/r/reference).
In more complicated cases, where your custom geom cannot be converted to a lower level geom, a custom method for the `geom2trace()` generic is required (`methods(geom2trace)` lists all the basic geoms that we natively support). This method should involve a conversion from a data frame to a list-like object conforming to the [plotly.js figure reference](https://plot.ly/r/reference).