# Load necessary libraries
library(plotly)
## Loading required package: ggplot2
## 
## Attaching package: 'plotly'
## The following object is masked from 'package:ggplot2':
## 
##     last_plot
## The following object is masked from 'package:stats':
## 
##     filter
## The following object is masked from 'package:graphics':
## 
##     layout
# Load the dataset
data("USArrests")

# Extract values from the second column
assault_arrests <- USArrests[, 2]

# Create a data frame with state names and corresponding assault arrests
state_data <- data.frame(State = row.names(USArrests), AssaultArrests = assault_arrests)

# Sort the data frame by the frequency of assault arrests in descending order
state_data <- state_data[order(-state_data$AssaultArrests), ]

# Create an interactive bivariate scatter chart using plotly
scatter_chart <- plot_ly(data = state_data, x = ~State, y = ~AssaultArrests,
                         type = "scatter", mode = "markers",
                         marker = list(color = ~AssaultArrests, colorscale = "Greens"),
                         text = ~paste("State: ", State, "<br>Assault Arrests: ", AssaultArrests),
                         hoverinfo = "text")

# Set layout options
layout_options <- list(
  title = "Interactive Bivariate Scatter Chart of Assault Arrests by State",
  xaxis = list(title = "State", tickangle = 45, showgrid = FALSE),
  yaxis = list(title = "Assault Arrests"),
  showlegend = FALSE
)

# Display the chart
scatter_chart <- layout(scatter_chart, layout_options)
scatter_chart