plotly_modify_legend: [!] Modify legend of a 'plotly' object

Description Usage Arguments Details Value Author(s) See Also Examples

View source: R/plotly_modify_legend.R

Description

Function allows modifying various legend options of object (plot) created with package plotly.

Usage

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
plotly_modify_legend(
  obj,
  showlegend = NULL,
  traceorder = NULL,
  bgcolor = NULL,
  bordercolor = NULL,
  borderwidth = NULL,
  fontcolor = NULL,
  fontfamily = NULL,
  fontsize = NULL,
  x = NULL,
  y = NULL,
  yanchor = NULL,
  xanchor = NULL,
  tracegroupgap = NULL,
  orientation = NULL,
  rm_rep_text = TRUE,
  rm_nonfirst_gr = TRUE,
  unique.legend = TRUE,
  ...,
  rm_repText = rm_rep_text
)

Arguments

obj

a plotly object (created with function plot_ly, ggplotly, subplot or similar).

showlegend

logical, which determins if will be shown. If NULL (default) value of this option will not be changed.

traceorder

Any combination of "reversed", "grouped" joined with a "+" OR "normal". examples: "reversed", "grouped", "reversed+grouped", "normal" Determines the order at which the legend items are displayed. If "normal", the items are displayed top-to-bottom in the same order as the input data. If "reversed", the items are displayed in the opposite order as "normal". If "grouped", the items are displayed in groups (when a trace 'legendgroup' is provided). if "grouped+reversed", the items are displayed in the opposite order as "grouped". Described in R plotly reference.

bgcolor

Legend's background color. If NULL (default) value of this option will not be changed.

bordercolor

Legend's border color. If NULL (default) value of this option will not be changed.

borderwidth

Legend's border width. If NULL (default) value of this option will not be changed.

fontcolor

Legend's font color. If NULL (default) value of this option will not be changed.

fontfamily

Legend's font family. If NULL (default) value of this option will not be changed.

fontsize

Legend's font size. If NULL (default) value of this option will not be changed.

x

Legend's x position. If NULL (default) value of this option will not be changed.

y

Legend's y position. If NULL (default) value of this option will not be changed.

yanchor

Described in R plotly reference.

xanchor

Described in R plotly reference.

tracegroupgap

Described in R plotly reference.

orientation

"v","h". If NULL (default) value of this option will not be changed. Described in R plotly reference.

rm_rep_text, rm_repText

(logical) If TRUE (default), repeated text in legend's label is removed.

rm_nonfirst_gr

(logical) If TRUE (default), non-first groups in legend's label is removed, e.g., "(ratio = 1.8,1,NA)" is converted to "ratio = 1.8".

unique.legend

logical. If TRUE (default), only one legend per legend group is shown. Result is visible if function subplot was applied.

...

Further parameters to methods.

Details

If option rm_repText is TRUE (default), function corrects text in legend of object created with function ggplotly so that only relevant information is displayed. For example, if the text in a label is "(matrix,matrix,matrix)", it is converted to shorter string "matrix".

Value

An updated plotly object (class plotly).

Author(s)

Vilmantas Gegzna

See Also

Online reference https://plot.ly/r/reference/#layout-legend;
Functions layout(), plot_ly(),

Other spPlot functions for plotly: label_expr2text(), plotly_annotation_rm(), plotly_modify_hover(), plotly_tidy()

Examples

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
library(spPlot)
library(spHelper)
library(hyperSpec)
library(plotly)

# Create `plotly` object:
obj <- qplot_spStat(chondro, "clusters", mean) %>%
   label_expr2text() %>%
   ggplotly()

# Then compare this plot:
plotly_modify_legend(obj)

# With the original one:
print(obj)

# More options
plotly_modify_legend(obj, traceorder = "reversed")
plotly_modify_legend(obj, showlegend = FALSE)

GegznaV/spPlot documentation built on April 29, 2020, 11:06 p.m.