8000 uniformtext · plotly/plotly.r-docs@db3af38 · GitHub
[go: up one dir, main page]

Skip to content

Commit db3af38

Browse files
author
mahdis-z
committed
uniformtext
1 parent fde8002 commit db3af38

File tree

1 file changed

+28
-0
lines changed

1 file changed

+28
-0
lines changed

r/2015-07-30-text-and-annotations.Rmd

Lines changed: 28 additions & 0 deletions
< F3E4 /tr>
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,34 @@ fig <- fig %>% layout(xaxis = list(range = c(1.6, 3.2)),
6262
fig
6363
```
6464

65+
### Controlling text fontsize with uniformtext
66+
67+
For the [pie](/r/pie-charts), [bar](/r/bar-charts), [sunburst](/r/sunburst-charts) and [treemap](/r/treemap-charts) traces, it is possible to force all the text labels to have the same size thanks to the `uniformtext` layout parameter. The `minsize` attribute sets the font size, and the `mode` attribute sets what happens for labels which cannot fit with the desired fontsize: either `hide` them or `show` them with overflow.
68+
69+
```{r}
70+
library(plotly)
71+
72+
df <- read.csv("https://raw.githubusercontent.com/plotly/datasets/master/gapminderDataFiveYear.csv", stringsAsFactors = FALSE)
73+
df <- df[which(df$year==2007 & df$continent=='Europe' & df$pop > 2.e6),]
74+
75+
fig <- plot_ly(df, type='bar', x = ~country, y = ~pop, text = ~lifeExp, name="",
76+
hovertemplate = paste('%{x}', '<br>lifeExp: %{text:.2s}<br>'),
77+
texttemplate = '%{y:.2s}', textposition = 'outside')
78+
79+
fig <- fig %>% layout(uniformtext=list(minsize=8, mode='hide'))
80+
fig
81+
```
82+
83+
```{r}
84+
library(plotly)
85+
86+
df <- read.csv("https://raw.githubusercontent.com/plotly/datasets/master/gapminderDataFiveYear.csv", stringsAsFactors = FALSE)
87+
df <- df[which(df$year==2007 & df$continent=='Asia'),]
88+
89+
fig <- plot_ly(df, type='pie', labels = ~country, values = ~pop, textposition = 'inside')
90+
fig <- fig %>% layout(uniformtext=list(minsize=12, mode='hide'))
91+
fig
92+
````
6593
### Adding Informations to Default Hover Text
6694
6795
```{r}

0 commit comments

Comments
 (0)
0