Create a web page presentation using R Markdown that features a plot created with Plotly. Host your webpage on either GitHub Pages, RPubs, or NeoCities.
This assignment demonstrates various data visualization techniques using Plotly in R Markdown.
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
# Generate sample data
data <- data.frame(
x = rnorm(100),
y = rnorm(100)
)
# Create scatter plot
plot_ly(data, x = ~x, y = ~y, type = "scatter", mode = "markers") %>%
layout(title = "Scatter Plot Example")
## 3D Scatter Plot
# Generate 3D sample data
data_3d <- data.frame(
x = rnorm(100),
y = rnorm(100),
z = rnorm(100)
)
# Create 3D scatter plot
plot_ly(data_3d, x = ~x, y = ~y, z = ~z, type = "scatter3d", mode = "markers") %>%
layout(
title = "3D Scatter Plot Example",
scene = list(
xaxis = list(title = "X-axis"),
yaxis = list(title = "Y-axis"),
zaxis = list(title = "Z-axis")
)
)
## Bar Chart
# Generate bar chart data
bar_data <- data.frame(
category = c("A", "B", "C", "D"),
value = c(22, 28, 26, 30)
)
# Create bar chart
plot_ly(bar_data, x = ~category, y = ~value, type = "bar",
marker = list(color = c("blue", "green", "orange", "red"))) %>%
layout(
title = "Bar Chart Example",
xaxis = list(title = "Categories"),
yaxis = list(title = "Values")
)
## Box Plot
# Generate box plot data
box_data <- data.frame(
group = rep(c("Group A", "Group B"), each = 100),
value = rnorm(200)
)
# Create box plot
plot_ly(box_data, y = ~value, color = ~group, type = "box",
colors = c("darkblue", "darkred")) %>%
layout(
title = "Box Plot Example",
yaxis = list(title = "Values")
)