This function is meant to be used with plotly
charts to quickly format them according to the San Mateo County Office of Epidemiology and Evaluation's style guide
Usage
theme_pl_smc(plot,
plot_lines = "horizontal",
legend_loc = "top",
ystart = "tozero",
title = NULL,
x_lab = NULL,
y_lab = NULL)
Arguments
- plot
A
plotly
plot object- plot_lines
Specify which lines should appear on your chart. The default is horizontal lines, but you can also choose:
"horizontal"
(the default): only horizontal lines"vertical"
: only vertical lines"both"
: horizontal and vertical lines"none"
: no lines on the plot
- legend_loc
Specify the legend location. The default is for the legend to appear at the top, but you can override this. The available options are: “left”,“top”, “right”, “bottom” and "none"
- ystart
Specify whether or not the y-axis should start at zero. The default is to start at zero. The options are:
"tozero"
(the default) : axis starts at 0"none"
: axis starts wherever plotly decides
- title
a string of text for the plot title
- x_lab
a string of text for the x-axis label
- y_lab
a string of tect for the y-axis label
Examples
if (FALSE) { # \dontrun{
library(plotly)
library(dplyr)
title <- "Sepal Lengths of Iris Species"
x <- "Species"
y <- "Sepal Length"
iris_vals <- iris %>%
distinct(Species) %>%
mutate(number = as.numeric(Species))
iris %>%
plot_ly() %>%
add_markers(x = ~jitter(as.numeric(Species)), y = ~Sepal.Length,
color = ~Species,
marker = list(size = 6),
hoverinfo = "text",
text = ~paste0("Group: ", Species,
"<br>xval: ", Sepal.Length),
showlegend = FALSE) %>%
layout(xaxis = list(tickvals = iris_vals$number,
ticktext = iris_vals$Species)) %>%
theme_pl_smc(plot_lines = "vertical",
title = title,
x_lab = x,
y_lab = y)
} # }