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

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语言数据分析:火箭发射的地点、日期/时间和结果分析的更多相关文章
- 吴裕雄--天生自然 python语言数据分析:开普勒系外行星搜索结果分析
import pandas as pd pd.DataFrame({'Yes': [50, 21], 'No': [131, 2]}) pd.DataFrame({'Bob': ['I liked i ...
- 吴裕雄--天生自然 R语言开发学习:R语言的安装与配置
下载R语言和开发工具RStudio安装包 先安装R
- 吴裕雄--天生自然 R语言开发学习:数据集和数据结构
数据集的概念 数据集通常是由数据构成的一个矩形数组,行表示观测,列表示变量.表2-1提供了一个假想的病例数据集. 不同的行业对于数据集的行和列叫法不同.统计学家称它们为观测(observation)和 ...
- 吴裕雄--天生自然 R语言数据可视化绘图(3)
par(ask=TRUE) opar <- par(no.readonly=TRUE) # record current settings # Listing 11.1 - A scatter ...
- 吴裕雄--天生自然 R语言开发学习:使用键盘、带分隔符的文本文件输入数据
R可从键盘.文本文件.Microsoft Excel和Access.流行的统计软件.特殊格 式的文件.多种关系型数据库管理系统.专业数据库.网站和在线服务中导入数据. 使用键盘了.有两种常见的方式:用 ...
- 吴裕雄--天生自然 R语言开发学习:R语言的简单介绍和使用
假设我们正在研究生理发育问 题,并收集了10名婴儿在出生后一年内的月龄和体重数据(见表1-).我们感兴趣的是体重的分 布及体重和月龄的关系. 可以使用函数c()以向量的形式输入月龄和体重数据,此函 数 ...
- 吴裕雄--天生自然 R语言开发学习:基础知识
1.基础数据结构 1.1 向量 # 创建向量a a <- c(1,2,3) print(a) 1.2 矩阵 #创建矩阵 mymat <- matrix(c(1:10), nrow=2, n ...
- 吴裕雄--天生自然 R语言开发学习:图形初阶(续二)
# ----------------------------------------------------# # R in Action (2nd ed): Chapter 3 # # Gettin ...
- 吴裕雄--天生自然 R语言开发学习:图形初阶(续一)
# ----------------------------------------------------# # R in Action (2nd ed): Chapter 3 # # Gettin ...
随机推荐
- CertUtil: -hashfile 失败: 0xd00000bb (-805306181)
使用CertUtil验证Python安装文件的时候出现了这个错误. CertUtil: -hashfile 失败: 0xd00000bb (-805306181) 代码是这样 certutil -ha ...
- flask框架-大结局
flask-script 用于实现类似于django中 python3 manage.py runserver ...类似的命令. 安装 pip3 install flask-script 使用: f ...
- Linux--Centos 下搭建 gitolite
参考:http://blog.csdn.net/zhangjs0322/article/details/32711211 http://gitolite.com/gitolite/fool_p ...
- idea中maven项目依赖jar一直标红线
网上maven仓库中无法下载某些jar包,这时候就需要手动下载,并导入maven, 导入命令demo: mvn install:install-file -DgroupId=javax.media - ...
- ios swift 判断uiviewcontroller时push present 进来的 还是pop进来的
override func viewWillAppear(_ animated: Bool) { super.viewWillAppear(animated) //显示navbar self.navi ...
- spring 事物面试题
1.spring 事物管理器中事物传播机制 2.spring中事物的隔离级别 读未提交-事物未提交,另一个事物可以读取到,脏读 读已提交-事物已提交,先前读取的数据与后来读取的数据不同,不可重复读 可 ...
- Linux 标准IO库介绍
1.标准IO和文件IO有什么区别? (1).看起来使用时都是函数,但是:标准IO是C库函数,而文件IO是Linux系统的API. (2).C语言库函数是由API封装而来的.库函数内部也是通过调用API ...
- 架构之道(3) - 令後端的吐血和喊FUCK的次数锐减
「那个产品经理不会技术,整天在需求,真操他妈的.」 这是很多产品经理遇到的一句话,如果你把顾客阶段完成了,回到自己的团队,遇到个技术大牛这麽说,那就表示,自己作为产品经理的功力还不够. 等我慢现解释, ...
- selector.xml的使用
TextView: <TextView android:id="@+id/resetfragment_btn" app:layout_constraintTop_toBott ...
- 什么是MTF曲线
MTF(Modulation Transfer Function)是衡量镜头性能的一个重要指标.将镜头把被摄体所具有的对比度再现到像面上的忠诚度以空间频率特性进行表示,便绘成了MTF曲线图. 曲线图的 ...