Instructions: Create a web page presentation using R Markdown that features a plot created with Plotly.
knitr::opts_chunk$set(echo = TRUE)
#required library
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
set.seed(123)
data <- data.frame(
x = rnorm(100),
y = rnorm(100),
group = sample(c("A", "B", "C"), 100, replace = TRUE)
)
#creating scatterplot
plot_ly(data, x = ~x, y = ~y, color = ~group, type = "scatter", mode = "markers") %>%
layout(title = "Scatter Plot", xaxis = list(title = "X"), yaxis = list(title = "Y"))
#sample data
data <- data.frame(
category = c("A", "B", "C"),
value = c(10, 20, 30)
)
#create bar chart
plot_ly(data, x = ~category, y = ~value, type = "bar", name = "Value") %>%
layout(title = "Bar Chart", xaxis = list(title = "Category"), yaxis = list(title = "Value"))
data("iris")
plot_ly(x= iris$Sepal.Width, y= iris$Sepal.Length, z = iris$Species,
type = "scatter3d", mode = "markers", color = iris$Species)