Skip to content

Instantly share code, notes, and snippets.

@pravj
Last active June 13, 2017 21:52
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save pravj/9ade57d31aa64a0bbdaa to your computer and use it in GitHub Desktop.
Save pravj/9ade57d31aa64a0bbdaa to your computer and use it in GitHub Desktop.
Source code for the post "Gauge charts in R and Python" [R version]
library(plotly)
base_plot <- plot_ly(
type = "pie",
values = c(40, 10, 10, 10, 10, 10, 10),
labels = c("-", "0", "20", "40", "60", "80", "100"),
rotation = 108,
direction = "clockwise",
hole = 0.4,
textinfo = "label",
textposition = "outside",
hoverinfo = "none",
domain = list(x = c(0, 0.48), y = c(0, 1)),
marker = list(colors = c('rgb(255, 255, 255)', 'rgb(255, 255, 255)', 'rgb(255, 255, 255)', 'rgb(255, 255, 255)', 'rgb(255, 255, 255)', 'rgb(255, 255, 255)', 'rgb(255, 255, 255)')),
showlegend = FALSE
)
base_plot <- add_trace(
base_plot,
type = "pie",
values = c(50, 10, 10, 10, 10, 10),
labels = c("Error Log Level Meter", "Debug", "Info", "Warn", "Error", "Fatal"),
rotation = 90,
direction = "clockwise",
hole = 0.3,
textinfo = "label",
textposition = "inside",
hoverinfo = "none",
domain = list(x = c(0, 0.48), y = c(0, 1)),
marker = list(colors = c('rgb(255, 255, 255)', 'rgb(232,226,202)', 'rgb(226,210,172)', 'rgb(223,189,139)', 'rgb(223,162,103)', 'rgb(226,126,64)')),
showlegend= FALSE
)
base_plot <- layout(
base_plot,
shapes = list(
list(
type = 'path',
path = 'M 0.235 0.5 L 0.24 0.62 L 0.245 0.5 Z',
xref = 'paper',
yref = 'paper',
fillcolor = 'rgba(44, 160, 101, 0.5)'
)
),
annotations = list(
list(
xref = 'paper',
yref = 'paper',
x = 0.23,
y = 0.45,
showarrow = FALSE,
text = '50'
)
)
)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment