This has been a really tough week for me, in general my toughest semester to keep up with my scheduling for all my classes in general. Performing this assignment has really shown me how much I’m liking interacting with data and visualizations. I found this data that wasn’t too overwhelming to analyze. I found it interesting since it covered a lot of models that I didn’t know about that. Finding what variables to play with was fun as well, and learning that I can make them more interactive with any user brings a lot of potential to future plots that I make. Instead of having to show everything in the plot, text, subtexts, and risk of it feeling too cluttered, providing interactivity this way feels refreshing.
library(tidyverse)
library(ggplot2)
library(plotly)
# Load data here
smartphones <- read.csv("smartphones.csv")
head(smartphones)
Do the following:
geom_point()).ggplot(smartphones, aes(x = RAM, y = Final.Price, color = Brand)) +
geom_point(size = 3) +
labs(
title = "Smartphone Price vs RAM",
x = "RAM",
y = "Final Price",
color = "Brand"
) +
theme_minimal()
## Warning: Removed 483 rows containing missing values or values outside the scale range
## (`geom_point()`).
ggplot(smartphones, aes(x = Brand, fill = Brand)) +
geom_bar() +
labs(
title = "Distribution of Smartphone Brands",
x = "Brand",
y = "Count"
) +
theme_minimal() +
theme(axis.text.x = element_text(angle = 45, hjust = 1))
ggplotly().ggplotly(
ggplot(smartphones, aes(x = RAM, y = Final.Price, color = Brand)) +
geom_point(size = 3) +
labs(
title = "Smartphone Price vs RAM",
x = "RAM",
y = "Final Price",
color = "Brand"
) +
theme_minimal()
)
ggplotly(
ggplot(smartphones, aes(x = Brand, fill = Brand)) +
geom_bar() +
labs(
title = "Distribution of Smartphone Brands",
x = "Brand",
y = "Count"
) +
theme_minimal() +
theme(axis.text.x = element_text(angle = 45, hjust = 1))
)
interactive_plot <- ggplotly(
ggplot(smartphones, aes(x = RAM, y = Final.Price, color = Brand, text = paste("Model:", Model, "<br>Storage:", Storage, "GB", "<br>Color:", Color))) +
geom_point(size = 3) +
labs(
title = "Smartphone Price vs RAM",
x = "RAM",
y = "Final Price",
color = "Brand"
) +
theme_minimal()
) %>%
layout(hoverlabel = list(bgcolor = "skyblue"))
interactive_plot <- interactive_plot %>%
layout(hovermode = 'closest') %>%
style(hoverinfo = "text")
interactive_plot
Good luck and have fun!
Install the {flexdashboard} package and create a new R Markdown file in your project by going to File > New File… > R Markdown… > From Template > Flexdashboard.
Using the documentation for {flexdashboard} online, create a basic dashboard that shows a plot (static or interactive) in at least three chart areas. Play with the layout if you’re feeling brave.