R语言课程论文-飞机失事数据可视化分析

数据来源:Airplane Crashes Since 1908 (kaggle.com)

代码参考:Exploring historic Air Plane crash data | Kaggle

数据指标及其含义

指标名

含义

Date

事故发生日期(年-月-日)

Time

当地时间,24小时制,格式为hh:mm

Location

事故发生的地点

Operator

航空公司或飞机的运营商

Flight

由飞机操作员指定的航班号

Route

事故前飞行的全部或部分航线

Type

飞机类型

Registration

国际民航组织对飞机的登记

cn/In

结构号或序列号/线号或机身号

Aboard

机上人数

Fatalities

死亡人数

Ground

地面死亡人数

Summary

事故的简要描述和原

library(tidyverse)
library(lubridate)
library(plotly)
library(gridExtra)
library(usmap)
library(igraph)
library(tidytext)
library(tm)
library(SnowballC)
library(wordcloud)
library(RColorBrewer)
library(readxl)df<- read.csv('F:\\Airplane_Crashes_and_Fatalities_Since_1908.csv',stringsAsFactors = FALSE)
df <- as_tibble(df)
head(df)
dim(df)
colnames(df)
df[is.na(df)] <- 0
df$Date <- mdy(df$Date)
df$Time <- hm(df$Time)
df$Year <- year(df$Date)
df$Month <- as.factor(month(df$Date))
df$Day <- as.factor(day(df$Date))
df$Weekday <- as.factor(wday(df$Date))
df$Week_no <- as.factor(week(df$Date))
df$Quarter <- as.factor(quarter(df$Date))
df$Is_Leap_Year <- leap_year(df$Date)
df$Decade <- year(floor_date(df$Date, years(10)))
df$Hour <- as.integer(hour(df$Time))
df$Minute <- as.factor(minute(df$Time))
df$AM_PM <- if_else(am(df$Time), 'AM', 'PM')
df$btwn_6PM_6AM <- if_else(df$Hour <= 6 | df$Hour >= 18, '6PM-6AM', '6AM-6PM')
year_wise <- df %>% count(Year)
day_wise <- df %>% count(Day) 
week_day_wise <- df %>% count(Weekday)
month_wise <- df %>% count(Month)
week_no_wise <- df %>% count(Week_no)
q_wise <- df %>% count(Quarter)
hour_wise <- df %>% count(Hour)
am_pm_wise <- df %>% count(AM_PM)
btwn_6PM_6AM_wise <- df %>% count(btwn_6PM_6AM)
Fatalities_wise <- df %>% count(Fatalities)
#图1:自1980年来每年失事飞机失事次数柱状图
ggplot(year_wise, aes(x = Year, y = n)) +geom_col(fill = '#0f4c75', col = 'white') +labs(title = '自1908年以来每年发生的飞机失事次数', x = '', y = '') +scale_x_continuous(breaks = seq(1908, 2020, 4))

#图2:失事飞机失事次数柱状图(按一周第几天、一月第几天统计)
wd <- ggplot(week_day_wise, aes(x = Weekday, y = n)) +geom_col(fill = '#3b6978', col = 'white')+labs(title = '按周的每一天统计飞机失事次', x = '', y = '')
d <- ggplot(day_wise, aes(x = Day, y = n)) +geom_col(fill = '#b83b5e', col = 'white')+labs(title = '按月的每一天统计飞机失事次', x = '', y = '')
grid.arrange(wd, d, nrow = 1, widths = c(1, 3))

#图3:失事飞机失事次数柱状图(按一年第几月、第几周、第几季度统计)
m <- ggplot(month_wise, aes(x = Month, y = n)) +geom_col(fill = '#ffcb74', col = 'white') +labs(title = '按月统计', x = '', y = '')
wn <- ggplot(week_no_wise, aes(x = Week_no, y = n)) +geom_col(fill = '#4f8a8b', col = 'white') +labs(title = '按周统计', x = '', y = '') 
q <- ggplot(q_wise, aes(x = Quarter, y = n)) +geom_col(fill = '#ea907a', col = 'white') +labs(title = '按季度统计', x = '', y = '')
grid.arrange(m, wn, q, nrow = 1, widths = c(2, 5, 1))

#图4:失事飞机失事次数柱状图(按一天第几小时、一天中上下午度统计)
h <- ggplot(hour_wise, aes(x = Hour, y = n)) +geom_col(fill = '#BD956A') +labs(title = '按小时统计', x = '', y = '')
a <- ggplot(am_pm_wise, aes(x = AM_PM, y = n, fill = AM_PM)) +geom_col() + labs(title = '上午-下午', x = '', y = '') +scale_fill_brewer(palette = "Set1") +theme(legend.position = "none") 
n <- ggplot(btwn_6PM_6AM_wise, aes(x = btwn_6PM_6AM, y = n, fill = btwn_6PM_6AM)) +geom_col() +labs(title = '白天&夜间', x = '', y = '') +scale_fill_brewer(palette = "Dark2") + theme(legend.position = "none") 
grid.arrange(h, a, n, nrow = 1, layout_matrix = rbind(c(1,1,1,1,2),c(1,1,1,1,3)))

#图5:失事飞机型号统计条形图
# 按类型分组
type_wise <- df %>%count(Type, sort = TRUE)
#按制造商提取和分组
main_type_wise <- df %>%#用空字符串替换型号mutate(main_type = str_replace_all(Type, "[A-Za-z]*-?\\d+-?[A-Za-z]*.*", "")) %>% count(main_type, sort = TRUE) %>%# 跳过空字符串行filter(main_type > 'A') 
options(repr.plot.width = 12)
# 失事飞机的型号排名(前20)
ggplot(head(type_wise, 20), aes(reorder(Type, n) , n, fill = n)) +geom_col(fill = 'deepskyblue2') +  geom_text(aes(label = n), hjust = 1.5, colour = "white", size = 5, fontface = "bold") +labs(title = '失事飞机的型号统计', x = '', y = '') +coord_flip()

#图6:失事飞机制造商统计条形图
ggplot(head(main_type_wise, 10), aes(reorder(main_type, n), n, fill = n)) +geom_col(fill = 'deepskyblue2') +geom_text(aes(label = n), hjust = 1.5, colour = "white", size = 5, fontface = "bold") +labs(title = '失事飞机的制造商统计', x = '', y = '')+    coord_flip()

#图7:失事飞机(包括军事飞机)运营商统计条形图
#运营商统计
operator_wise <- df %>%count(Operator, sort = TRUE)
#商业运营商表
main_op_wise <- df %>%# replace all group of words followed by '-'mutate(main_op = str_replace_all(Operator, ' -.*', '')) %>% filter(!str_detect(main_op, '[Mm]ilitary')) %>%filter(!str_detect(main_op, 'Private')) %>%count(main_op, sort = TRUE) %>%filter(main_op > 'A') 
# 提取军事飞行数据
force <- operator_wise %>%filter(str_detect(Operator, '[Mm]ilitary')) %>%mutate(op = str_replace_all(Operator, 'Military ?-? ?', '')) %>%count(op, sort = TRUE)
#提取军事飞机所属国家
force_country <- operator_wise %>%# 获取包含字符串“军用”的行'military'filter(str_detect(Operator, 'Military|military')) %>%# 将带有包含国家信息的字符串替换为国家名mutate(op = str_replace_all(Operator, 'Royal Air Force', 'UK')) %>%mutate(op = str_replace_all(op, 'Military ?-? ?|Royal', '')) %>%mutate(op = str_replace_all(op, ' (Navy|Army|Air|Maritime Self Defense|Marine Corps|Naval|Defence|Armed) ?.*', '')) %>%mutate(op = str_replace_all(op, '.*U\\.? ?S\\.?.*|United States|American', 'USA')) %>%mutate(op = str_replace_all(op, 'Aeroflot ?/? ?', '')) %>%mutate(op = str_replace_all(op, '.*Republic? ?of', '')) %>%mutate(op = str_replace_all(op, '.*British.*', 'UK')) %>%mutate(op = str_replace_all(op, '.*Indian.*', 'Indian')) %>%mutate(op = str_replace_all(op, '.*Chin.*', 'Chinese')) %>%mutate(op = str_replace_all(op, '.*Chilean.*', 'Chilian')) %>%mutate(op = str_replace_all(op, '.*Iran.*', 'Iran')) %>%mutate(op = str_replace_all(op, '.*French.*', 'French')) %>%mutate(op = str_replace_all(op, '.*Ecuador.*', 'Ecuadorean')) %>%mutate(op = str_replace_all(op, '.*Zambia.*', 'Zambian')) %>%mutate(op = str_replace_all(op, '.*Russia.*', 'Russian')) %>%mutate(op = str_replace_all(op, '.*Afghan.*', 'Afghan')) %>%group_by(op) %>%summarize(n = sum(n)) %>%arrange(desc(n)) 
#军用飞行与非军用飞行
yr_military <- df %>%select(Year, Operator) %>%mutate(Is_Military = str_detect(Operator, 'Military|military')) %>%group_by(Year, Is_Military) %>%summarize(n = n())
ggplot(head(operator_wise, 10), aes(reorder(Operator, n) , n, fill = n))+geom_col(fill = 'coral3')+labs(title='失事飞机(包括军事飞机在内)的运营商统计', x = '', y = '')+  geom_text(aes(label = n), hjust = 1.5, colour = "white", size = 5, fontface = "bold")+coord_flip()

#图8:失事飞机(不包括军事飞机)运营商统计条形图
ggplot(head(main_op_wise, 10), aes(reorder(main_op, n) , n, fill=n)) +geom_col(fill='coral2') +labs(title='失事商业飞机(不包括军事飞机)的商业运营商统计', x='', y='') +  geom_text(aes(label = n), hjust = 1.5, colour = "white", size = 5, fontface = "bold") +coord_flip()

#图9:军事飞机所属军队、所属国家统计条形图
f <- ggplot(head(force, 10), aes(reorder(op, n) , n, fill = n))+geom_col(fill = 'cyan4')+labs(title = '军事飞机失事统计', x = '', y = '')+  geom_text(aes(label = n), hjust = 1.5, colour = "white", size = 5, fontface = "bold")+coord_flip()
fc <- ggplot(head(force_country, 10), aes(reorder(op, n) , n, fill = n))+geom_col(fill = 'cyan3')+labs(title = '军事飞机失事的国家排名', x = '', y = '')+  geom_text(aes(label = n), hjust = 1.5, colour = "white", size = 5, fontface = "bold")+coord_flip()
grid.arrange(f,fc, nrow = 1, widths = c(1, 1))

#图10:自1980年来军事飞机与非军事失事次数柱状图
ggplot(yr_military, aes(x = Year, y = n, fill = Is_Military)) +geom_col(col = 'white') +labs(title = '失事飞机是否为军用飞机?',x = '', y = '', fill = '') +scale_x_continuous(breaks = seq(1908, 2020, 4)) + scale_fill_brewer(palette = "Dark2") +theme(legend.position = "top", legend.justification = "left")

#图11:飞机失事地点统计条形图
take_off_dest <- df %>%select('Route') %>%filter(Route!='') %>%filter(str_detect(Route, ' ?- ?')) %>%mutate(Take_Off = str_extract(Route, '[^-]* ?-?')) %>%mutate(Take_Off = str_replace(Take_Off, ' -', ''))%>%mutate(Destination = str_extract(Route, '- ?[^-]*$')) %>%mutate(Destination = str_replace(Destination, '- ?', ''))
route <- take_off_dest %>% count(Route, sort = TRUE)
take_off <- take_off_dest %>% count(Take_Off, sort = TRUE)
dest <- take_off_dest %>% count(Destination, sort = TRUE)
r <- ggplot(head(route, 15), aes(reorder(Route, n) , n, fill=n))+geom_col(fill='#E59CC4')+labs(title='飞行途中失事路线', x='', y='')+  geom_text(aes(label=n), hjust = 1.5, colour="white", size=5, fontface="bold")+coord_flip()
t <- ggplot(head(take_off, 15), aes(reorder(Take_Off, n) , n, fill=n))+geom_col(fill='#005082')+labs(title='起飞时飞机失事地点', x='', y='')+  geom_text(aes(label=n), hjust = 1.5, colour="white", size=5, fontface="bold")+coord_flip()
d <- ggplot(head(dest, 15), aes(reorder(Destination, n) , n, fill=n))+geom_col(fill='#ff6363')+labs(title='落地时飞机失事地点', x='', y='')+  geom_text(aes(label=n), hjust = 1.5, colour="white", size=5, fontface="bold")+coord_flip()
options(repr.plot.width = 18)
grid.arrange(r,t,d, nrow = 1, widths=c(1,1,1))

#图12:全球范围内飞机失事热力图
cntry <- cntry %>%mutate(m = case_when(n >= 100  ~ "100 +",n < 100 & n >= 70 ~ "70 - 100",n < 70 & n >= 40 ~ "40 - 70",n < 40 & n >= 10 ~ "10 - 40",n < 10  ~ "< 10")) %>%mutate(m = factor(m, levels = c("< 10", "10 - 40", "40 - 70", "70 - 100", "100 +")))
world_map <- map_data("world")
map_data <- cntry %>% full_join(world_map, by = c('Country' = 'region')) 
options(repr.plot.width = 18, repr.plot.height = 9)
map_pal = c("#7FC7AF", "#E4B363",'#EF6461',"#E97F02",'#313638')
ggplot(map_data, aes(x = long, y = lat, group = group, fill = m)) +geom_polygon(colour = "white") + labs(title = '全球范围内飞机失事热力图', x = '', y = '', fill = '') +scale_fill_manual(values = map_pal, na.value = 'whitesmoke') + theme(legend.position='right', legend.justification = "top") + guides(fill = guide_legend(reverse = TRUE))

#图13:飞机失事原因词云图
data <- read_excel("F:\\summary.xlsx")
corpus <- Corpus(VectorSource(data))
corpus <- tm_map(corpus, content_transformer(tolower))
corpus <- tm_map(corpus, removePunctuation)
corpus <- tm_map(corpus, removeNumbers)
corpus <- tm_map(corpus, removeWords, stopwords("english"))dtm <- TermDocumentMatrix(corpus)
word_freqs <- rowSums(as.matrix(dtm))
wordcloud(names(word_freqs), word_freqs, min.freq = 1, max.words=150,words_distance=0.001,random.order=FALSE,font_path='msyh.ttc',
rot.per=0.05,colors=brewer.pal(8, "Dark2"), backgroundColor = "grey",shape = 'circle',width=3, height=9)

ps:低价出课程论文-多元统计分析论文、R语言论文、stata计量经济学课程论文(论文+源代码+数据集)

本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如若转载,请注明出处:http://www.mzph.cn/news/687649.shtml

如若内容造成侵权/违法违规/事实不符,请联系多彩编程网进行投诉反馈email:809451989@qq.com,一经查实,立即删除!

相关文章

CCF GESP 2024年3月认证时间及费用价格

1、认证语言&#xff1a; C/Python/图形化编程 2、报名及缴费时间&#xff1a; 2024年1月18日17点至3月5日24点截止 3、认证时间&#xff1a; 1-4级 2024年3月16日 上午09:30-11:30 5-8级 2024年3月16日 下午13:30-16:30 4、认证方式&#xff1a; 全国各GESP考点内上…

在客户端隔离的情况下通过 airtun-ng 实现直接客户端注入

直接的客户端注入技术 当我们试图执行一次无线攻击时&#xff0c;一个常见的问题就是&#xff0c;网络上的AP接入点拒绝在攻击者和被攻击者之间互转他们之间的攻击数据包。这种拒绝担任“中继”(relay)角色&#xff0c;而避免网络客户端之间互相攻击的技术&#xff0c;被称为“…

实例观察 c 语言中 volatile 的作用

volatile 意思是易变的。 在 c 语言中&#xff0c;如果变量被 volatile 修饰&#xff0c;就是告诉编译器这个变量随时都可能发生变化&#xff0c;那么每次读取变量的时候都会到内存中读取。 如果变量没有被 volatile 修饰&#xff0c;并且编译器发现在多次读取变量之间&#…

备战蓝桥杯---图论之建图基础

话不多说&#xff0c;直接看题&#xff1a; 首先&#xff0c;这个不是按照字典序的顺序&#xff0c;而是以只要1先做&#xff0c;在满足后让2先做。。。。 就是让数字小的放前面做拓扑排序。 我们可以先做1&#xff0c;看看它的前驱。 举个例子&#xff1a; 我们肯定要把1放…

JVM常见问题笔记分享

文章目录 1 JVM组成1.1 JVM由那些部分组成&#xff0c;运行流程是什么&#xff1f;1.2 什么是程序计数器&#xff1f;1.3 你能给我详细的介绍Java堆吗?元空间(MetaSpace)介绍 1.4 什么是虚拟机栈1.5 堆和栈的区别1.6 能不能解释一下方法区&#xff1f;1.5.1 概述1.5.2 常量池1…

项目一:高并发内存池

1. 项目介绍 1.1 这个项目是做什么的 当前项目是实现一个高并发的内存池&#xff0c;他的原型是 google 的一个 开源项目tcmalloc &#xff0c; tcmalloc 全称 Thread-Caching Malloc &#xff0c;即线程缓存的 malloc &#xff0c;实现了高效的多线程内存管理&#xff0c;用…

蓝桥杯备赛_python_BFS搜索算法_刷题学习笔记

1 bfs广度优先搜索 1.1 是什么 1.2怎么实现 2案例学习 2.1.走迷宫 2.2.P1443 马的遍历 2.3. 九宫重排&#xff08;看答案学的&#xff0c;实在写不来&#xff09; 2.4.青蛙跳杯子&#xff08;学完九宫重排再做bingo&#xff09; 2.5. 长草 3.总结 1 bfs广度优先搜索 【P…

1.初识Tauri

文章目录 一、前言二、基本认识三、js与rust通信四、构建应用 一、前言 原文以及后续文章可点击查看&#xff1a;初识Tauri。 Tauri是一款比较新的跨平台桌面框架&#xff0c;也是我目前最喜欢的一个框架&#xff0c;其官网为&#xff1a;Tauri 它的作用其实和Electron很像&…

【PyQt】在PyQt5的界面上集成matplotlib绘制的图像

文章目录 0 前期教程1 概述2 matplotlib2.1 库导入2.2 图片的各个部分解释2.3 代码风格2.4 后端 3 集成matplotlib图像到pyqt界面中3.1 使用到的模块3.2 理解Qt Designer中的“控件提升”3.3 界面与逻辑分离的思路3.4 扩展 0 前期教程 【PyQt】PyQt5进阶——串口上位机及实时数…

transformer-Attention is All You Need(一)

1. 为什么需要transformer 循环模型通常沿输入和输出序列的符号位置进行因子计算。通过在计算期间将位置与步骤对齐&#xff0c;它们根据前一步的隐藏状态和输入产生位置的隐藏状态序列。这种固有的顺序特性阻止了训练样本内的并行化&#xff0c;这在较长的序列长度上变得至关重…

STM32-开发工具

开发过程中可能用到的工具 1、烧录下载调试工具ST-LINK ST-LINK&#xff0c;是ST(意法半导体)推出的调试编程工具&#xff0c;适用于STM32系列芯片的USB接口的下载及在线仿真器。 2、串口调试工具/串口下载工具 串口调试工具是一种用于通过串口通信协议与目标设备进行数据交…

源码网打包,目前有3000多个资源

源码网打包&#xff0c;目前有3000多个资源 需要赶快下手吧&#xff0c;到手可以使用&#xff0c;搭建好和本站一样&#xff0c;全网唯一 优化缩略图演示&#xff1a;https://www.htm.ink默认缩略图演示&#xff1a;https://blog.htm.ink网站截图

c入门第十六篇——学生成绩管理系统

师弟&#xff1a;“师兄&#xff0c;我最近构建了一个学生成绩管理系统&#xff0c;有空试用一下么&#xff1f;” 我&#xff1a;“好啊&#xff01;” 一个简单的学生成绩管理系统&#xff0c;基本功能包括&#xff1a;添加学生信息、显示所有学生信息、按学号查找学生信息、…

网络安全习题集

第一章 绪论 4 ISO / OSI 安全体系结构中的对象认证安全服务使用&#xff08; C ) 机制来完成。 A &#xff0e;访问控制 B &#xff0e;加密 C &#xff0e;数字签名 D &#xff0e;数据完整性 5 身份鉴别是安全服务中的重要一环&#xff0c;以下关于身份鉴别的叙述不正确的是…

const--类的常量成员函数

在C中,为了禁止成员函数修改数据成员的值,可以将它设置为常量成员函数。设置常量成员函数的方法是在函数原型的后面加上const,形式如下: class x { …………… T f(t1,t2) const{} ………… }; 常量成员函数的作用&#xff1a; 将成员函数设置为const&#xff0c;表明该成员函…

FMEA的六大分类——SunFMEA软件

FMEA是一种预防性的质量工具&#xff0c;通过对产品设计或过程的故障模式进行分析&#xff0c;评估其可能产生的影响&#xff0c;从而采取相应的措施来降低产品的故障风险。根据分析的范围和目的&#xff0c;FMEA可以分为以下几种类型&#xff0c;今天sun fmea软件系统和大家一…

理解孟子思想,传承中华文化

为了更好地了解和传承中华文化&#xff0c;加深对孟子思想的认识与理解&#xff0c;探究孟子思想在现代社会的传承与发展&#xff0c;2024年2月18日&#xff0c;曲阜师范大学计算机学院“古韵新声&#xff0c;格物致‘知’”实践队队员崔本迪在山东省泰安市东平县进行了深入的调…

vue-路由(六)

阅读文章你可以收获什么&#xff1f; 1 明白什么是单页应用 2 知道vue中的路由是什么 3 知道如何使用vueRouter这个路由插件 4 知道如何如何封装路由组件 5 知道vue中的声明式导航router-link的用法 6 知道vue中的编程式导航的使用 7 知道声明式导航和编程式导航式如何传…

代码随想录算法训练营第33天| Leetcode1005.K次取反后最大化的数组和、134. 加油站、135. 分发糖果

文章目录 Leetcode 1005.K次取反后最大化的数组和Leetcode 134. 加油站Leetcode 135. 分发糖果 Leetcode 1005.K次取反后最大化的数组和 题目链接&#xff1a;Leetcode 1005.K次取反后最大化的数组和 题目描述&#xff1a; 给你一个整数数组 nums 和一个整数 k &#xff0c;按…

动态规划之编辑距离(接上一个题)

给定 n 个长度不超过 1010 的字符串以及 m 次询问&#xff0c;每次询问给出一个字符串和一个操作次数上限。 对于每次询问&#xff0c;请你求出给定的 n 个字符串中有多少个字符串可以在上限操作次数内经过操作变成询问给出的字符串。 每个对字符串进行的单个字符的插入、删除…