Warning: package 'dslabs' was built under R version 4.3.3
library(RColorBrewer)library(tidyverse)
── Attaching core tidyverse packages ──────────────────────── tidyverse 2.0.0 ──
✔ dplyr 1.1.4 ✔ readr 2.1.5
✔ forcats 1.0.0 ✔ stringr 1.5.1
✔ ggplot2 3.4.4 ✔ tibble 3.2.1
✔ lubridate 1.9.3 ✔ tidyr 1.3.1
✔ purrr 1.0.2
── Conflicts ────────────────────────────────────────── tidyverse_conflicts() ──
✖ dplyr::filter() masks stats::filter()
✖ dplyr::lag() masks stats::lag()
ℹ Use the conflicted package (<http://conflicted.r-lib.org/>) to force all conflicts to become errors
library(ggthemes)
Warning: package 'ggthemes' was built under R version 4.3.3
library(ggrepel)
Warning: package 'ggrepel' was built under R version 4.3.3
library(plotly)
Warning: package 'plotly' was built under R version 4.3.3
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
above I load the proper packages needed
I then decide that from the dslabs data set Id like to do stars.
data("stars")
Introduction
For this data set I chose to work with stars as I wanted to see how the magnitude of a star effected the temperature of a star. For this I wanted to make a scatter plot and for the scatter plot I really wanted to show it for each star type. So for this I first took the took the top 45 stars as I feel that would make the graph less cluttered.
Organizing data
Here bellow I extract the top 45 stars so I can use them in my data.
topstars <-head(stars, 45) #extract the top 45 rows of stars in the data set and insert them into "Top stars."
Making the Graph
Bellow I begin to make the graph, I use the murder data set example from the class notes to do this and use it as a building block to form this graph. I also used the plotly example for more building blocks.
p1 <-ggplot(topstars, aes(x = magnitude, y= temp/1000 ,text =paste ("star name:", star))) +geom_point(aes(color=type)) +labs(title ="Temperature Vs Magnitude in Stars", caption ="Source:DSlabs Stars Data set", color="Star Type") +xlab("Magnitude Of Star") +ylab ("Temperature Of Star (In Thousands)") +theme_clean()p2 <-ggplotly(p1)p2
Conclusion
In my graph I used the data set of stars as astronomy has always interested and I was very curious to see how the magnitude of a star effected the temperature or vice versa. In my graph I really wanted to play with interactivity and I did this by whenever you hover over a point you can see the star name and information with the star. I used the theme clean for this graph as I thought it looked very nice and it did. Overall I am happy with this graph and I want to keep on using plotly in the future.