dfS = read.csv("F:\\kaggleDataSet\\spacex-missions\\database.csv")

library(dplyr)
library(tidyr)
library(data.table)
library(sqldf)
library(highcharter)
library(ggrepel)
library(leaflet)
library(viridisLite)
library(countrycode)
library(ggplot2)
names(dfS) <- gsub("\\.", "", names(dfS))
dfS$CustomerCountry = sub(x = dfS$CustomerCountry, pattern = "France (Mexico)", replacement = "France", fixed=T) dfS = data.table(sqldf(c("UPDATE dfS SET PayloadType = PayloadName WHERE PayloadType == ''",
"SELECT * FROM main.dfS"), method = "raw"))
dfS = data.table(sqldf(c("UPDATE dfS SET PayloadOrbit = 'Unknown' WHERE PayloadOrbit == ''",
"SELECT * FROM main.dfS"), method = "raw"))
dfS = data.table(sqldf(c("UPDATE dfS SET CustomerName = 'N/A' WHERE CustomerName == ''", "SELECT * FROM main.dfS"),
method = "raw"))
dfS = data.table(sqldf(c("UPDATE dfS SET CustomerType = 'N/A' WHERE CustomerType == ''", "SELECT * FROM main.dfS"),
method = "raw"))
dfS = data.table(sqldf(c("UPDATE dfS SET CustomerCountry = 'N/A'WHERE CustomerCountry == ''",
"SELECT * FROM main.dfS"), method = "raw"))
dfS$PayloadMasskg[is.na(dfS$PayloadMasskg)] <- 'Unknown' dfS = as.data.frame(dfS)
date.chr <- as.character(dfS$LaunchDate)
date <- strptime(date.chr,format="%d %b %Y")
dfS$LaunchDate = date
dfS$LaunchDate = as.Date(dfS$LaunchDate)

hchart(dfS$CustomerCountry, colorByPoint = TRUE, name = "Customer's country") %>%
hc_title(text = "SpaceX Missions by the country of customer") %>% hc_add_theme(hc_theme_flat()) %>%
hc_credits(enabled = TRUE, text = "Sources: SpaceX, NASA", style = list(fontSize = "10px"))

hchart(dfS$CustomerName, colorByPoint = TRUE, name = "Name of the customer") %>%
hc_title(text = "SpaceX Missions by name of the customer") %>% hc_add_theme(hc_theme_ffx()) %>%
hc_credits(enabled = TRUE, text = "Sources: SpaceX, NASA", style = list(fontSize = "10px"))

hchart(dfS$LaunchSite, colorByPoint = TRUE, name = "Launch site") %>%
hc_title(text = "SpaceX Missions by launch site") %>% hc_add_theme(hc_theme_ffx()) %>%
hc_credits(enabled = TRUE, text = "Sources: SpaceX, NASA", style = list(fontSize = "10px"))

hchart(dfS$PayloadType, colorByPoint = TRUE, name = "Type of Paylod") %>%
hc_title(text = "SpaceX Missions by type of Payload") %>% hc_add_theme(hc_theme_ffx()) %>%
hc_credits(enabled = TRUE, text = "Sources: SpaceX, NASA", style = list(fontSize = "10px"))

hchart(dfS$MissionOutcome, colorByPoint = TRUE, name = "Mission outcome") %>%
hc_title(text = "SpaceX Missions by mission outcome") %>% hc_add_theme(hc_theme_ffx()) %>%
hc_credits(enabled = TRUE, text = "Sources: SpaceX, NASA", style = list(fontSize = "10px"))

ggplot(dfS)+ geom_point(aes(VehicleType, LaunchDate), size = 5, color = 'grey60') +
geom_label_repel(aes(VehicleType, LaunchDate, fill = ifelse(dfS$MissionOutcome == 'Failure', 'Failure', 'Success'),
label = PayloadMasskg),fontface = 'bold', color = 'white', size = 6, box.padding = unit(0.35, "lines"),
point.padding = unit(0.5, "lines"),segment.color = 'grey50') +
ggtitle("SpaceX missions outcome by Year, Vehicle and Payload mass in KG")+ labs(x="Vehicle type",y="Year") +
theme(legend.title = element_text(face = "bold", size = 16)) + theme(legend.text = element_text(size = 16)) +
theme(legend.position = "bottom")+ labs(fill = "Mission Outcome") +
theme(plot.title = element_text(size = 22, face = "bold")) +
theme(axis.text=element_text(size=13), axis.title=element_text(size=16,face="bold"))

ggplot(dfS)+ geom_point(aes(LaunchSite, LaunchDate), size = 4, color = 'grey60') +
geom_label_repel(aes(LaunchSite, LaunchDate, fill = ifelse(dfS$MissionOutcome == 'Failure', 'Failure', 'Success'),
label = VehicleType), fontface = 'bold', color = 'white', size = 4, box.padding = unit(0.35, "lines"),
point.padding = unit(0.5, "lines"),segment.color = 'grey50') +
ggtitle("SpaceX missions outcome by Year, Launch site and Vehicle type")+ labs(x="Launch site",y="Year") +
theme(legend.title = element_text(face = "bold", size = 16)) + theme(legend.text = element_text(size = 16)) +
theme(legend.position = "bottom")+ labs(fill = "Mission Outcome") +
theme(plot.title = element_text(size = 22, face = "bold")) +
theme(axis.text=element_text(size=13), axis.title=element_text(size=16,face="bold"))

ggplot(dfS)+ geom_point(aes(LaunchSite, LaunchDate), size = 5, color = 'grey60') +
geom_label_repel(aes(LaunchSite, LaunchDate, fill = ifelse(dfS$MissionOutcome == 'Failure', 'Failure', 'Success'),
label = PayloadType), fontface = 'bold', color = 'white', size = 5, box.padding = unit(0.35, "lines"),
point.padding = unit(0.5, "lines"),segment.color = 'grey50') +
ggtitle("SpaceX missions outcome by Year, Launch Site and Payload Type")+ labs(x="Launch site",y="Year") +
theme(legend.title = element_text(face = "bold", size = 16)) + theme(legend.text = element_text(size = 16)) +
theme(legend.position = "bottom")+ labs(fill = "Mission Outcome") +
theme(plot.title = element_text(size = 22, face = "bold")) +
theme(axis.text=element_text(size=13), axis.title=element_text(size=16,face="bold"))

ggplot(dfS)+ geom_point(aes(VehicleType, LaunchDate), size = 5, color = 'grey60') +
geom_label_repel(aes(VehicleType, LaunchDate, fill = ifelse(dfS$MissionOutcome == 'Failure', 'Failure', 'Success'),
label = PayloadOrbit), fontface = 'bold', color = 'white', size = 5, box.padding = unit(0.35, "lines"),
point.padding = unit(0.5, "lines"),segment.color = 'grey50') +
ggtitle("SpaceX missions outcome by Year, Vehicle type and Payload Orbit")+ labs(x="Vehicle type",y="Year") +
theme(legend.title = element_text(face = "bold", size = 16)) + theme(legend.text = element_text(size = 16)) +
theme(legend.position = "bottom")+ labs(fill = "Mission Outcome") +
theme(plot.title = element_text(size = 22, face = "bold")) +
theme(axis.text=element_text(size=13), axis.title=element_text(size=16,face="bold"))

ggplot(dfS)+ geom_point(aes(CustomerType, LaunchDate), size = 5, color = 'grey60') +
geom_label_repel(aes(CustomerType, LaunchDate, fill = ifelse(dfS$MissionOutcome == 'Failure', 'Failure', 'Success'),
label = CustomerCountry), fontface = 'bold', color = 'white', size = 6, box.padding = unit(0.35, "lines"),
point.padding = unit(0.5, "lines"),segment.color = 'grey50') +
ggtitle("SpaceX missions outcome by Year, Customer type and Customer's country")+ labs(x="Customer type",y="Year") +
theme(legend.title = element_text(face = "bold", size = 16)) + theme(legend.text = element_text(size = 16)) +
theme(legend.position = "bottom")+ labs(fill = "Mission Outcome") +
theme(plot.title = element_text(size = 22, face = "bold")) +
theme(axis.text=element_text(size=13), axis.title=element_text(size=16,face="bold"))

ggplot(dfS)+ geom_point(aes(VehicleType, LaunchTime), size = 5, color = 'grey60') +
geom_label_repel(aes(VehicleType, LaunchTime, fill = ifelse(dfS$MissionOutcome == 'Failure', 'Failure', 'Success'),
label = CustomerName), fontface = 'bold', color = 'white', size = 6, box.padding = unit(0.35, "lines"),
point.padding = unit(0.5, "lines"),segment.color = 'grey50') +
ggtitle("SpaceX missions outcome by Launch time, Vehicle type and Customer's name")+ labs(x="Vehicle type",y="Launch time") +
theme(legend.title = element_text(face = "bold", size = 16)) + theme(legend.text = element_text(size = 16)) +
theme(legend.position = "bottom")+ labs(fill = "Mission Outcome") +
theme(plot.title = element_text(size = 22, face = "bold")) +
theme(axis.text=element_text(size=13), axis.title=element_text(size=16,face="bold"))

ggplot(dfS)+ geom_point(aes(CustomerCountry, LaunchTime), size = 5, color = 'grey60') +
geom_label_repel(aes(CustomerCountry, LaunchTime, fill = ifelse(dfS$MissionOutcome == 'Failure', 'Failure', 'Success'),
label = CustomerName), fontface = 'bold', color = 'white', size = 6, box.padding = unit(0.35, "lines"),
point.padding = unit(0.5, "lines"),segment.color = 'grey50') +
ggtitle("SpaceX missions outcome by Launch time, Customer's country and Customer's name")+
labs(x="Customer's country",y="Launch time") +
theme(legend.title = element_text(face = "bold", size = 16)) + theme(legend.text = element_text(size = 16)) +
theme(legend.position = "bottom")+ labs(fill = "Mission Outcome") +
theme(plot.title = element_text(size = 22, face = "bold")) +
theme(axis.text=element_text(size=13), axis.title=element_text(size=16,face="bold"))

dfS$PayloadMasskg = as.integer(dfS$PayloadMasskg)

ggplot(dfS)+ geom_point(aes(LaunchDate, PayloadMasskg), size = 5, color = 'grey60') +
geom_label_repel(aes(LaunchDate, PayloadMasskg, fill = ifelse(dfS$MissionOutcome == 'Failure', 'Failure', 'Success'),
label = CustomerCountry), fontface = 'bold', color = 'white', size = 6, box.padding = unit(0.35, "lines"),
point.padding = unit(0.5, "lines"),segment.color = 'grey50') +
ggtitle("SpaceX missions outcome by Year, Payload mass in KG and Customer's country")+ labs(x="Year",y="Payload mass in KG") +
theme(legend.title = element_text(face = "bold", size = 16)) + theme(legend.text = element_text(size = 18)) +
theme(legend.position = "bottom")+ labs(fill = "Mission Outcome") +
theme(plot.title = element_text(size = 22, face = "bold")) +
theme(axis.text=element_text(size=13), axis.title=element_text(size=16,face="bold"))

吴裕雄--天生自然 R语言数据分析:火箭发射的地点、日期/时间和结果分析的更多相关文章

  1. 吴裕雄--天生自然 python语言数据分析:开普勒系外行星搜索结果分析

    import pandas as pd pd.DataFrame({'Yes': [50, 21], 'No': [131, 2]}) pd.DataFrame({'Bob': ['I liked i ...

  2. 吴裕雄--天生自然 R语言开发学习:R语言的安装与配置

    下载R语言和开发工具RStudio安装包 先安装R

  3. 吴裕雄--天生自然 R语言开发学习:数据集和数据结构

    数据集的概念 数据集通常是由数据构成的一个矩形数组,行表示观测,列表示变量.表2-1提供了一个假想的病例数据集. 不同的行业对于数据集的行和列叫法不同.统计学家称它们为观测(observation)和 ...

  4. 吴裕雄--天生自然 R语言数据可视化绘图(3)

    par(ask=TRUE) opar <- par(no.readonly=TRUE) # record current settings # Listing 11.1 - A scatter ...

  5. 吴裕雄--天生自然 R语言开发学习:使用键盘、带分隔符的文本文件输入数据

    R可从键盘.文本文件.Microsoft Excel和Access.流行的统计软件.特殊格 式的文件.多种关系型数据库管理系统.专业数据库.网站和在线服务中导入数据. 使用键盘了.有两种常见的方式:用 ...

  6. 吴裕雄--天生自然 R语言开发学习:R语言的简单介绍和使用

    假设我们正在研究生理发育问 题,并收集了10名婴儿在出生后一年内的月龄和体重数据(见表1-).我们感兴趣的是体重的分 布及体重和月龄的关系. 可以使用函数c()以向量的形式输入月龄和体重数据,此函 数 ...

  7. 吴裕雄--天生自然 R语言开发学习:基础知识

    1.基础数据结构 1.1 向量 # 创建向量a a <- c(1,2,3) print(a) 1.2 矩阵 #创建矩阵 mymat <- matrix(c(1:10), nrow=2, n ...

  8. 吴裕雄--天生自然 R语言开发学习:图形初阶(续二)

    # ----------------------------------------------------# # R in Action (2nd ed): Chapter 3 # # Gettin ...

  9. 吴裕雄--天生自然 R语言开发学习:图形初阶(续一)

    # ----------------------------------------------------# # R in Action (2nd ed): Chapter 3 # # Gettin ...

随机推荐

  1. Vus the Cossack and Strings(Codeforces Round #571 (Div. 2))(大佬的位运算实在是太强了!)

    C. Vus the Cossack and Strings Vus the Cossack has two binary strings, that is, strings that consist ...

  2. 2.docker machine 创建 包含 docker 的 linux 虚拟机

    1. 启动 从https://github.com/boot2docker/boot2docker/releases下载iso到~/.docker/machine/cache/里 docker-mac ...

  3. 吴裕雄--天生自然 pythonTensorFlow图形数据处理:读取MNIST手写图片数据写入的TFRecord文件

    import numpy as np import tensorflow as tf from tensorflow.examples.tutorials.mnist import input_dat ...

  4. TPO3-1Architecture

    Much of the world's great architecture has been constructed of stone because of its beauty, permanen ...

  5. [ZJOI2019]浙江省选(半平面交)

    一眼看上去就应该能用半平面交去做. 首先考虑怎么求可能得第1名的人:每个人的函数为直线,就是在所有人的半平面交中的上边界者即可获得第一名,这个可以单调队列求解. 再考虑如何求可能得第2名的人:满足2个 ...

  6. flash插件的安装——网页视频无法播放

    1.从官网下载Adobe flash player 安装包.官方网址:https://get.adobe.com/cn/flashplayer/ 或者从我的网盘下载:链接:https://pan.ba ...

  7. Spring IOC 和AOP

    Spring是什么? Spring是一个轻量级的IoC和AOP容器框架. IOC:IOC就是控制反转,控制反转指的是把创建对象和管理对象之间的依赖关系交给了IOC容器来管理.以前new对象由程序员来控 ...

  8. [Algo] 26. Kth Smallest Number In Sorted Matrix

    Given a matrix of size N x M. For each row the elements are sorted in ascending order, and for each ...

  9. 吴裕雄--天生自然C语言开发:文件读写

    #include <stdio.h> int main() { FILE *fp = NULL; fp = fopen("/tmp/test.txt", "w ...

  10. locate及find查找命令

    在文件系统上查找符合条件的文件:       实现工具:locate,find locate:       依赖于事先构建好的索引库:       系统自动实现(周期性任务):       手动更新数 ...