# R Plotly Area Plot

**URL:** <https://community.plotly.com/t/r-plotly-area-plot/48791>\
**Category:** Dash R\
**Created:** [January 7, 2021, 10:19pm UTC](https://community.plotly.com/t/r-plotly-area-plot/48791 "2021-01-07T22:19:30Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![abick](https://avatars.discourse-cdn.com/v4/letter/a/278dde/32.png) [@abick](https://community.plotly.com/u/abick)\
**Post date:** [January 7, 2021, 10:19pm UTC](https://community.plotly.com/t/r-plotly-area-plot/48791/1 "2021-01-07T22:19:30Z")

</div>

Hello,  
I am attempting to create a filled area plot using the code copied from here [Filled Area Plots | R | Plotly](https://plotly.com/r/filled-area-plots/#interior-filling-for-area-chart)

My chart looks like this:

 ![image](https://us1.discourse-cdn.com/flex024/uploads/plot/original/2X/e/e22619026af3d651903e05b58e6841ea710ea6d3.png)

The data looks like this:

```auto
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:

```auto
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

---

<div class="post-metadata">

**Author:** ![ismirsehregal](https://sea2.discourse-cdn.com/flex024/user_avatar/community.plotly.com/ismirsehregal/32/6794_2.png) [@ismirsehregal](https://community.plotly.com/u/ismirsehregal)\
**Post date:** [January 8, 2021, 9:40am UTC](https://community.plotly.com/t/r-plotly-area-plot/48791/2 "2021-01-08T09:40:40Z")

</div>

Looks good to me:

```auto
library(plotly)

f.ribbonData <- structure(list(period = c("M01", "M02", "M03", "M04", "M05", 
"M06", "M07", "M08", "M09", "M10", "M11", "M12"), periodName = c("January", 
"February", "March", "April", "May", "June", "July", "August", 
"September", "October", "November", "December"), minUI = c("0.033", 
"0.031", "0.028", "0.026", "0.025", "0.029", "0.028", "0.028", 
"0.027", "0.027", "0.027", "0.027"), maxUI = c("0.08", "0.079", 
"0.075", "0.071", "0.07", "0.073", "0.068", "0.064", "0.062", 
"0.062", "0.06", "0.059"), midUI = c("0.0565", "0.055", "0.0515", 
"0.0485", "0.0475", "0.051", "0.048", "0.046", "0.0445", "0.0445", 
"0.0435", "0.043")), class = "data.frame", row.names = c(NA, -12L))

f.ribbonData$periodName <- factor(f.ribbonData$periodName,
 levels = c("January", "February", "March","April", "May", "June",
 "July", "August", "September", "October", "November", "December"))

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))
fig

```

* * *

Result:

![image](https://us1.discourse-cdn.com/flex024/uploads/plot/original/2X/2/28017b9899c7b74044b69c65139c3804c572051b.png)

---

<div class="post-metadata">

**Author:** ![abick](https://avatars.discourse-cdn.com/v4/letter/a/278dde/32.png) [@abick](https://community.plotly.com/u/abick)\
**Post date:** [January 8, 2021, 3:22pm UTC](https://community.plotly.com/t/r-plotly-area-plot/48791/3 "2021-01-08T15:22:46Z")

</div>

Thanks for the tip @ismirsehregal  
I was able to produce the desired chart by converting the tibble to a data.frame with this command:  
f.ribbonDataDF \<- as.data.frame(f.ribbonData)

One question I have is how to control the colors of bottom lines and makers. In the image, the color of the line is green and the makers are orange, despite the color attribute of the “minUI” line is the same as the "maxUI line (line = list(color = ‘rgba(0,100,80,1)’)

I’ll keep working on this. I would appreciate any suggestions about how to resolve this.  
Thanks again,  
AB

---

<div class="post-metadata">

**Author:** ![ismirsehregal](https://sea2.discourse-cdn.com/flex024/user_avatar/community.plotly.com/ismirsehregal/32/6794_2.png) [@ismirsehregal](https://community.plotly.com/u/ismirsehregal)\
**Post date:** [February 9, 2021, 12:18pm UTC](https://community.plotly.com/t/r-plotly-area-plot/48791/4 "2021-02-09T12:18:11Z")

</div>

Just provide the `color` argument on trace level (or add `marker = list(color = 'rgba(0,100,80,1)'`)

```auto
library(plotly)

f.ribbonData <- structure(list(period = c("M01", "M02", "M03", "M04", "M05", 
                                          "M06", "M07", "M08", "M09", "M10", "M11", "M12"), periodName = c("January", 
                                                                                                           "February", "March", "April", "May", "June", "July", "August", 
                                                                                                           "September", "October", "November", "December"), minUI = c("0.033", 
                                                                                                                                                                      "0.031", "0.028", "0.026", "0.025", "0.029", "0.028", "0.028", 
                                                                                                                                                                      "0.027", "0.027", "0.027", "0.027"), maxUI = c("0.08", "0.079", 
                                                                                                                                                                                                                     "0.075", "0.071", "0.07", "0.073", "0.068", "0.064", "0.062", 
                                                                                                                                                                                                                     "0.062", "0.06", "0.059"), midUI = c("0.0565", "0.055", "0.0515", 
                                                                                                                                                                                                                                                          "0.0485", "0.0475", "0.051", "0.048", "0.046", "0.0445", "0.0445", 
                                                                                                                                                                                                                                                          "0.0435", "0.043")), class = "data.frame", row.names = c(NA, -12L))

f.ribbonData$periodName <- factor(f.ribbonData$periodName,
                                  levels = c("January", "February", "March","April", "May", "June",
                                             "July", "August", "September", "October", "November", "December"))

fig <- plot_ly(f.ribbonData, x = ~periodName, y = ~maxUI, type = 'scatter', mode = 'lines+markers',
               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)', 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))
fig

```

 ![image](https://us1.discourse-cdn.com/flex024/uploads/plot/original/2X/a/afa1296e2a33f882d5c19a3cc1ffe0b9298f8a92.png)
