Introduction

What follows is a set of examples of California STD Surveillance data visualized using the plotly package for R. Add another descriptive sentence here.

#simple barchart
plot_ly(
  std_gg1,
  x= ~year,
  y= ~cases,
  color= ~sex,
  type="bar"
  # mode="bar"
) 
#bar chart - side by side vs stacked
plot_ly(
  std_gg1,
  x= ~year,
  y= ~cases,
  color= ~sex,
  type="bar"
) %>%
  layout(barmode="stack")
std_gg2a <- std_gg %>%
  filter(county != "California" & year=="2018" & sex=="Total") %>%
  select(county, disease_f, rate)

#boxplot
plot_ly(
  std_gg2a,
  y=~rate,
  color=~disease_f,
  type="box"
)
#trend over time in alameda county with confidence intervals
std_gg3 <- std_gg %>%
  filter(county=="Alameda" & sex=="Total")

#make a presentable table
plot_ly(
  std_gg3,
  x=~year,
  y=~rate,
  color=~disease_f,
  type="scatter",
  mode="lines",
  colors=c("darkorange","darkcyan","darkslateblue"),
  text = ~paste('Cases: ',cases,'<br>Population: ',population,'<br>Rate: ',rate)
) %>%
  layout(
    title="Alameda County STD Rates, 2001-2018",
    yaxis=list(title="Case Rate per 100,000"),
    xaxis=list(title="Year"),
    paper_bgcolor="azure",
    plot_bgcolor="white"
  )
#add trace example
std_gg3b <- std_gg %>%
  filter(county=="Alameda" & sex=="Total") %>%
  select(year,disease,rate) %>%
  pivot_wider(names_from=disease, values_from=rate)

plot_ly(
  std_gg3b,
  x=~year,
  y=~`Chlamydia`,
  name="Chlamydia",
  type="scatter",
  mode="markers"
) %>%
  add_trace(y=~`Gonorrhea`,name="Gonorrhea",mode="lines")%>%
  add_trace(y=~`Early Syphilis`,name="Early Syphilis",mode="lines+markers") %>%
  layout(yaxis=list(title="Rate per 100,000"))
#subplot example
plot1 <- plot_ly(std_gg3b,
                 x=~year,
                  y=~`Chlamydia`,
                  name="Chlamydia",
                  type="scatter")

plot2 <- plot_ly(std_gg3b,
                 x=~year,
                  y=~`Gonorrhea`,
                  name="Gonorrhea",
                  type="scatter")

subplot(plot1,plot2,nrows=2,shareX=T)
subplot(plot1,plot2,shareY=T)