Instantly share code, notes, and snippets.

@pravj /gauge-post.R
Last active Jun 13, 2017

Embed
What would you like to do?
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