I want to have a dashed line around bar in Plotly barplot R.
In the following code I had dash = 'dash' in line attribute but it's not working.
library(plotly)
x <- c('Product A', 'Product B', 'Product C')
y <- c(20, 14, 23)
text <- c('27% market share', '24% market share', '19% market share')
data <- data.frame(x, y, text)
fig <- plot_ly(data, x = ~x, y = ~y, type = 'bar', text = text,
marker = list(color = 'rgb(158,202,225)',
line = list(color = 'rgb(8,48,107)',
width = 1.5, dash = "dash")))
fig <- fig %>% layout(title = "January 2013 Sales Report",
xaxis = list(title = ""),
yaxis = list(title = ""))
fig
As of right now,
linein bar plot doesn't include the argument "dash". However, you can add a dashed line usingshapes.In the code, I've added comments to explain what does what. If there is anything that's unclear, let me know.
First, I calculate where the start and end of each of the bars are in
paperspace on the x-axis. By default thepaperspace of the plot, whether x or y axes is equal to 1. You have to divide one by the number of bars to get the start of each bar's 'space.' By default, there is a 10% space added before and after each bar. (You can manually change the space.)After calculating the start and end of each bar on the x-axis, I build the
shapesusing the typerect.When I create the bar plot, I leave out your original call for
linewithinmarker.Check it out: