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

2024-02-18 14:44

本文主要是介绍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计量经济学课程论文(论文+源代码+数据集)

这篇关于R语言课程论文-飞机失事数据可视化分析的文章就介绍到这儿,希望我们推荐的文章对编程师们有所帮助!



http://www.chinasem.cn/article/721486

相关文章

大模型研发全揭秘:客服工单数据标注的完整攻略

在人工智能(AI)领域,数据标注是模型训练过程中至关重要的一步。无论你是新手还是有经验的从业者,掌握数据标注的技术细节和常见问题的解决方案都能为你的AI项目增添不少价值。在电信运营商的客服系统中,工单数据是客户问题和解决方案的重要记录。通过对这些工单数据进行有效标注,不仅能够帮助提升客服自动化系统的智能化水平,还能优化客户服务流程,提高客户满意度。本文将详细介绍如何在电信运营商客服工单的背景下进行

基于MySQL Binlog的Elasticsearch数据同步实践

一、为什么要做 随着马蜂窝的逐渐发展,我们的业务数据越来越多,单纯使用 MySQL 已经不能满足我们的数据查询需求,例如对于商品、订单等数据的多维度检索。 使用 Elasticsearch 存储业务数据可以很好的解决我们业务中的搜索需求。而数据进行异构存储后,随之而来的就是数据同步的问题。 二、现有方法及问题 对于数据同步,我们目前的解决方案是建立数据中间表。把需要检索的业务数据,统一放到一张M

关于数据埋点,你需要了解这些基本知识

产品汪每天都在和数据打交道,你知道数据来自哪里吗? 移动app端内的用户行为数据大多来自埋点,了解一些埋点知识,能和数据分析师、技术侃大山,参与到前期的数据采集,更重要是让最终的埋点数据能为我所用,否则可怜巴巴等上几个月是常有的事。   埋点类型 根据埋点方式,可以区分为: 手动埋点半自动埋点全自动埋点 秉承“任何事物都有两面性”的道理:自动程度高的,能解决通用统计,便于统一化管理,但个性化定

使用SecondaryNameNode恢复NameNode的数据

1)需求: NameNode进程挂了并且存储的数据也丢失了,如何恢复NameNode 此种方式恢复的数据可能存在小部分数据的丢失。 2)故障模拟 (1)kill -9 NameNode进程 [lytfly@hadoop102 current]$ kill -9 19886 (2)删除NameNode存储的数据(/opt/module/hadoop-3.1.4/data/tmp/dfs/na

异构存储(冷热数据分离)

异构存储主要解决不同的数据,存储在不同类型的硬盘中,达到最佳性能的问题。 异构存储Shell操作 (1)查看当前有哪些存储策略可以用 [lytfly@hadoop102 hadoop-3.1.4]$ hdfs storagepolicies -listPolicies (2)为指定路径(数据存储目录)设置指定的存储策略 hdfs storagepolicies -setStoragePo

Hadoop集群数据均衡之磁盘间数据均衡

生产环境,由于硬盘空间不足,往往需要增加一块硬盘。刚加载的硬盘没有数据时,可以执行磁盘数据均衡命令。(Hadoop3.x新特性) plan后面带的节点的名字必须是已经存在的,并且是需要均衡的节点。 如果节点不存在,会报如下错误: 如果节点只有一个硬盘的话,不会创建均衡计划: (1)生成均衡计划 hdfs diskbalancer -plan hadoop102 (2)执行均衡计划 hd

性能分析之MySQL索引实战案例

文章目录 一、前言二、准备三、MySQL索引优化四、MySQL 索引知识回顾五、总结 一、前言 在上一讲性能工具之 JProfiler 简单登录案例分析实战中已经发现SQL没有建立索引问题,本文将一起从代码层去分析为什么没有建立索引? 开源ERP项目地址:https://gitee.com/jishenghua/JSH_ERP 二、准备 打开IDEA找到登录请求资源路径位置

【Prometheus】PromQL向量匹配实现不同标签的向量数据进行运算

✨✨ 欢迎大家来到景天科技苑✨✨ 🎈🎈 养成好习惯,先赞后看哦~🎈🎈 🏆 作者简介:景天科技苑 🏆《头衔》:大厂架构师,华为云开发者社区专家博主,阿里云开发者社区专家博主,CSDN全栈领域优质创作者,掘金优秀博主,51CTO博客专家等。 🏆《博客》:Python全栈,前后端开发,小程序开发,人工智能,js逆向,App逆向,网络系统安全,数据分析,Django,fastapi

科研绘图系列:R语言扩展物种堆积图(Extended Stacked Barplot)

介绍 R语言的扩展物种堆积图是一种数据可视化工具,它不仅展示了物种的堆积结果,还整合了不同样本分组之间的差异性分析结果。这种图形表示方法能够直观地比较不同物种在各个分组中的显著性差异,为研究者提供了一种有效的数据解读方式。 加载R包 knitr::opts_chunk$set(warning = F, message = F)library(tidyverse)library(phyl

透彻!驯服大型语言模型(LLMs)的五种方法,及具体方法选择思路

引言 随着时间的发展,大型语言模型不再停留在演示阶段而是逐步面向生产系统的应用,随着人们期望的不断增加,目标也发生了巨大的变化。在短短的几个月的时间里,人们对大模型的认识已经从对其zero-shot能力感到惊讶,转变为考虑改进模型质量、提高模型可用性。 「大语言模型(LLMs)其实就是利用高容量的模型架构(例如Transformer)对海量的、多种多样的数据分布进行建模得到,它包含了大量的先验