Skip to content

Commit 16b2933

Browse files
Merge pull request #3 from plotly/hover-text
Hover text
2 parents 79394fb + 08245db commit 16b2933

File tree

1 file changed

+32
-19
lines changed

1 file changed

+32
-19
lines changed

r/2018-01-29-hover-text-and-formatting.Rmd

Lines changed: 32 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,16 @@
11
---
2+
name: Hover Text and Formatting
3+
permalink: r/hover-text-and-formatting/
24
description: How to use hover text and formatting in R with Plotly.
3-
display_as: file_settings
4-
language: r
55
layout: base
6-
name: Hover Text and Formatting
6+
thumbnail: thumbnail/hover-text.jpg
7+
language: r
8+
display_as: file_settings
79
order: 7
10+
page_type: u-guide
811
output:
912
html_document:
1013
keep_md: true
11-
page_type: u-guide
12-
permalink: r/hover-text-and-formatting/
13-
thumbnail: thumbnail/hover-text.png
1414
---
1515

1616
```{r, echo = FALSE, message=FALSE}
@@ -66,22 +66,20 @@ p <- plot_ly(type = 'scatter', mode = 'markers') %>%
6666
showlegend = F
6767
) %>%
6868
layout(
69-
title = "Set hover text formatting<br><a href= https://github.com/d3/d3-time-format/blob/master/README.md#locale_format>https://github.com/d3/d3-time-format/blob/master/README.md#locale_format</a>",
70-
titlefont = list(
71-
size = 10
72-
),
73-
xaxis = list(
74-
zeroline = F
75-
),
76-
yaxis = list(
77-
hoverformat = '.2f'
78-
)
79-
)
69+
title = list(text="Set hover text formatting<br><a href= https://github.com/d3/d3-time-format/blob/master/README.md#locale_format>https://github.com/d3/d3-time-format/blob/master/README.md#locale_format</a>",
70+
size = 10),
71+
xaxis = list(zeroline = F),
72+
yaxis = list(hoverformat = '.2f'))
8073
8174
p
8275
```
8376

84-
#### Hovertemplate
77+
#### Customize Tooltip Text with a Hovertemplate
78+
79+
To customize the tooltip on your graph you can use [hovertemplate](https://plot.ly/r/reference/#pie-hovertemplate), which is a template string used for rendering the information that appear on hoverbox.
80+
This template string can include `variables` in %{variable} format, `numbers` in [d3-format's syntax](https://github.com/d3/d3-3.x-api-reference/blob/master/Formatting.md#d3_forma), and `date` in [d3-time-fomrat's syntax](https://github.com/d3/d3-3.x-api-reference/blob/master/Time-Formatting.md#format).
81+
Hovertemplate customize the tooltip text vs. [texttemplate](https://plot.ly/r/reference/#pie-texttemplate) which customizes the text that appears on your chart. <br>
82+
Set the horizontal alignment of the text within tooltip with [hoverlabel.align](https://plot.ly/r/reference/#layout-hoverlabel-align).
8583

8684
```{r}
8785
library(plotly)
@@ -110,6 +108,21 @@ p <- plot_ly() %>%
110108
p
111109
```
112110

111+
```{r}
112+
library(plotly)
113+
p <- plot_ly() %>%
114+
add_trace(
115+
type = "pie",
116+
name = "",
117+
values = c(2, 1, 3, 2.5),
118+
labels = c("R", "Python", "Java Script", "Matlab"),
119+
text = c("textA", "TextB", "TextC", "TextD"),
120+
hovertemplate = "%{label}: <br>Popularity: %{percent} </br> %{text}")
121+
122+
123+
p
124+
```
125+
113126
#### Advanced Hovertemplate
114127

115128
```{r}
@@ -141,4 +154,4 @@ p
141154

142155
#### Reference
143156

144-
See [https://plot.ly/r/reference/](https://plot.ly/r/reference/) for more information and options!
157+
See [https://plot.ly/r/reference/](https://plot.ly/r/reference/) for more information and options!

0 commit comments

Comments
 (0)