##Load Required Pacakges and dataset
library(plotly)
library(dplyr)
data("ChickWeight")
##Group chicks by diet type and calculate their mean weights on each day.
chicks <- ChickWeight %>%
group_by(Diet, Time) %>%
summarize(mean_wt = mean(weight))
##Create Plot
plot_ly(chicks, x=~Time, y=~mean_wt, color = ~Diet, type="scatter",
mode="lines",
name=paste("diet", chicks$Diet, sep=" ")) %>%
layout(
title = "Chick Weights by Diets",
xaxis = list(title = 'Days since Birth'),
yaxis = list(title = 'Mean Chick Weight (gram)'),
showlegend=TRUE
)