Hello,
I am attempting to create a filled area plot using the code copied from here Filled Area Plots | R | Plotly
My chart looks like this:
The data looks like this:
f.ribbonData
# A tibble: 12 x 5
# Groups: period [12]
period periodName minUI maxUI midUI
<chr> <fct> <dbl> <dbl> <dbl>
1 M01 January 0.033 0.08 0.0565
2 M02 February 0.031 0.079 0.055
3 M03 March 0.0280 0.075 0.0515
4 M04 April 0.026 0.071 0.0485
5 M05 May 0.025 0.07 0.0475
6 M06 June 0.0290 0.073 0.051
7 M07 July 0.0280 0.068 0.048
8 M08 August 0.0280 0.064 0.046
9 M09 September 0.027 0.062 0.0445
10 M10 October 0.027 0.062 0.0445
11 M11 November 0.027 0.06 0.0435
12 M12 December 0.027 0.059 0.043
I have defined periodName as a factor in month-order:
f.ribbonData$periodName <- factor(f.ribbonData$periodName,
levels = c(“January”, “February”, “March”,“April”, “May”, “June”,
“July”, “August”, “September”, “October”, “November”, “December”))
Finally, this is the code I used:
fig <- plot_ly(f.ribbonData, x = ~periodName, y = ~maxUI, type = 'scatter', mode = 'lines+markers',
line = list(color = 'rgba(0,100,80,1)'),
showlegend = FALSE, name = 'Max UI')
fig <- fig %>% add_trace(y = ~minUI, type = 'scatter', mode = 'lines+markers',
fill = 'tonexty', fillcolor='rgba(0,100,80,0.2)', line = list(color = 'rgba(0,100,80,1)'),
showlegend = FALSE, name = 'Min UI')
fig <- fig %>% layout(title = "Unemployment Rate",
paper_bgcolor='rgb(255,255,255)', plot_bgcolor='rgb(229,229,229)',
xaxis = list(title = "Months",
gridcolor = 'rgb(255,255,255)',
showgrid = TRUE,
showline = FALSE,
showticklabels = TRUE,
tickcolor = 'rgb(127,127,127)',
ticks = 'outside',
zeroline = FALSE),
yaxis = list(title = "Unemployment Rate",
gridcolor = 'rgb(255,255,255)',
showgrid = TRUE,
showline = FALSE,
showticklabels = TRUE,
tickcolor = 'rgb(127,127,127)',
ticks = 'outside',
zeroline = FALSE))
I cannot figure out why my chart does not look anything like the example.
Would appreciate any suggestions about how to make this work.
I used R version 4.0.3 (2020-10-10) and plotly version plotly_4.9.2.2
TIA
AB