This is an R Markdown document. Markdown is a simple formatting syntax for authoring HTML, PDF, and MS Word documents. For more details on using R Markdown see http://rmarkdown.rstudio.com.
When you click the Knit button a document will be generated that includes both content as well as the output of any embedded R code chunks within the document. You can embed an R code chunk like this:
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. Your webpage must contain the date that you created the document, and it must contain a plot created with Plotly.
library(plotly)
## Warning: package 'plotly' was built under R version 4.2.2
## Loading required package: ggplot2
## Warning: package 'ggplot2' was built under R version 4.2.2
##
## 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
library(dplyr)
##
## Attaching package: 'dplyr'
## The following objects are masked from 'package:stats':
##
## filter, lag
## The following objects are masked from 'package:base':
##
## intersect, setdiff, setequal, union
library(ggplot2)
library(tidyverse)
## ── Attaching packages
## ───────────────────────────────────────
## tidyverse 1.3.2 ──
## ✔ tibble 3.1.8 ✔ purrr 1.0.0
## ✔ tidyr 1.2.1 ✔ stringr 1.5.0
## ✔ readr 2.1.3 ✔ forcats 0.5.2
## Warning: package 'purrr' was built under R version 4.2.2
## Warning: package 'stringr' was built under R version 4.2.2
## ── Conflicts ────────────────────────────────────────── tidyverse_conflicts() ──
## ✖ dplyr::filter() masks plotly::filter(), stats::filter()
## ✖ dplyr::lag() masks stats::lag()
setwd("C:/Users/Aare Akin/Documents/R work/Coursera complete/Course 9 Developing")
space_missions_data <- read_csv("space_missions.csv")
## Rows: 4630 Columns: 9
## ── Column specification ────────────────────────────────────────────────────────
## Delimiter: ","
## chr (6): Company, Location, Rocket, Mission, RocketStatus, MissionStatus
## num (1): Price
## date (1): Date
## time (1): Time
##
## ℹ Use `spec()` to retrieve the full column specification for this data.
## ℹ Specify the column types or set `show_col_types = FALSE` to quiet this message.
p1 <- ggplot(space_missions_data, aes(x =MissionStatus))+
geom_bar()
ggplotly(p1)
Bar Chart
MissionStatus_df<- space_missions_data %>% count(MissionStatus)
plot_ly(MissionStatus_df, y =~n , x =~ MissionStatus, type = "bar")
plot_ly(MissionStatus_df, x= ~MissionStatus,y =~n, type = "bar", color = I("red"))
Trace
plot_ly(MissionStatus_df) %>%
add_trace( x= ~MissionStatus,y =~n, type = "bar", color = I("gray")) %>%
add_trace( x= ~MissionStatus,y =~n, type = "scatter", color = I("black")) %>%
add_text( x= ~MissionStatus,y =~n, text = ~n, color = I("tomato2"))
## No scatter mode specifed:
## Setting the mode to markers
## Read more about this attribute -> https://plotly.com/r/reference/#scatter-mode
plot_ly(MissionStatus_df) %>%
add_trace( x= ~MissionStatus,y =~n, type = "bar", color = I("gray")) %>%
add_text( x= ~MissionStatus,y =~n, text = ~n, color = I("tomato2")) %>%
layout(title = "Mission Status",
xaxis = list(title = "mission axis",
fixedrange = TRUE),
plot_bgcolor = "lightgreen",
paper_bgcolor = "gray",
yaxis = list(title = "y-axis",
fixedrange = TRUE),
legend = list(orientation = "h", # show entries horizontally
xanchor = "center", # use center of legend as anchor
x = 0.5,
y = -0.25))
plot_ly(MissionStatus_df) %>%
add_trace( x= ~MissionStatus,y =~n, type = "bar", color = I("gray")) %>%
config(displaylogo = FALSE)