I'd like to add annotation
to a scatter
plot generated by R
's plotly
package, and have the text appear in bold.
I'm trying:
library(plotly)
library(dplyr)
set.seed(1)
df <- data.frame(x=rnorm(10),y=rnorm(10))
plotly::plot_ly(x =~ df$x, y =~ df$y,marker = list(size=12), type = 'scatter',mode = "markers") %>%
plotly::add_annotations(text=1:10,showarrow=T,arrowhead=1,x=df$x,y=df$y,font=list(size=10))
Which gives:
Trying to add face="bold"
to the font
specification list
:
plotly::plot_ly(x =~ df$x, y =~ df$y,marker = list(size=12), type = 'scatter',mode = "markers") %>%
plotly::add_annotations(text=1:10,showarrow=T,arrowhead=1,x=df$x,y=df$y,font=list(size=10,face="bold"))
Doesn't really change anything:
So the question is how to get that text annotation to appear in bold.
P.S. In my real data I'd like to annotate clusters of points hence the annotations come as a separate layer.
One method for getting bold text is to change the font to Arial Black (or other bold font) which should be available on most systems. This method will scale a little easier to axes and other elements. Save this answer.
The default font family spec is "Open Sans", verdana, arial, sans-serif , as listed in Python Figure Reference: layout from the Plotly documentation. The precise font selected depends on which fonts you have installed on your system. If Open Sans is available, that font will be selected.
Simply enter your text as HTML, like so:
plotly::plot_ly(x =~ df$x, y =~ df$y,marker = list(size=12), type = 'scatter',mode = "markers") %>%
plotly::add_annotations(text=sprintf("<b>%s</b>", 1:10),showarrow=T,arrowhead=1,x=df$x,y=df$y,font=list(size=10))
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With