Ex 8 Using plotly

Works fine

p <- plot_ly(Combined3, x = Combined3$Years, y = Combined3$`Num Marriages`)  #produces a scatter
#p  

Produces a boxplot and this dosent work so well ==>> color = “Red”

p1 <- plot_ly(Combined3, x = Combined3$`Male initiated Divorce`,type = "box")  
#p1
colnames(Combined3)
## [1] "Years"                    "Num Marriages"           
## [3] "Num Divorces"             "Div Involving Children"  
## [5] "Male initiated Divorce"   "Female initiated Divorce"
##    This one works  , add xlab, ylab, mainlab, , ymin , ymax, xmin, xmax 

library(plotly)

trace_0 <-  Combined3$`Male initiated Divorce`            #rnorm(100, mean = 5)
trace_1 <-  Combined3$`Female initiated Divorce`             #rnorm(100, mean = 0)
trace_2 <-  Combined3$`Div Involving Children`   #rnorm(100, mean = -5)
trace_3 <-  Combined3$`Num Marriages`
x <-        Combined3$Years     #c(1996,2006,2012,2013,2014,2015,2016)

data <- data.frame(x, trace_0, trace_1, trace_2)

# This below sets the margins and plot size, see layout, height, width

m <- list(
  l = 20,
  r = 20,
  b = 80,
  t = 80,
  pad = 4    #4
)


p <- plot_ly(data, x = ~x, y = ~trace_0, name = 'Male initiated Divorce', type = 'scatter', mode = 'lines+markers') %>%  add_trace(y = ~trace_1, name = 'Female initiated Divorce', mode = 'lines+markers') %>%  add_trace(y = ~trace_2, name = 'Div Involving Children', mode = 'lines+markers') %>%  add_trace(y = ~trace_3, name = 'Num Marriages', mode = 'lines+markers') %>%
  layout(autosize = F, width = 700, height = 700, margin = m )   #, xlab('Years')
## Warning: Specifying width/height in layout() is now deprecated.
## Please specify in ggplotly() or plot_ly()
chart_link = api_create(p, filename="scatter-modes1")
## Found a grid already named: 'scatter-modes1 Grid'. Since fileopt='overwrite', I'll try to update it
## Found a plot already named: 'scatter-modes1'. Since fileopt='overwrite', I'll try to update it
chart_link

Conclusion

I found with plotly, if you uploaded the data you could manipulate the graph much more easily, I couldn’t find a way to add labels or a way to name the main heading , whereas if you uploaded the data , you could do these things.