当前位置:网站首页>R语言的画图代码及差异性分析[通俗易懂]
R语言的画图代码及差异性分析[通俗易懂]
2022-07-31 14:25:00 【全栈程序员站长】
大家好,又见面了,我是你们的朋友全栈君。
R语言结合统计学方法画图实现
例如:
提示:写完文章后,目录可以自动生成,如何生成可参考右边的帮助文档
文章目录
前言
加载我们常用的包,如ggplot2 , 在这里我只使用R的可视化功能,前期的数据清洗及处理,将数据转化为R可识别的数据格式, 我均是通过Python的pandas包来实现的,强烈推荐使用python清洗数据!!!! 自动化加星号!!!!(显著性!!!!)
提示:以下是本篇文章正文内容,下面案例可供参考
一、ggplot2是什么?
示例:ggplot2 是R语言可视化的一个包,可视化功能非常强大。
二、使用步骤
1.加载我们数据分析及画图所需要的的包
代码如下(示例):
library(xlsx)
library("Hmisc") ## to use "rcorr"
library(psych)
library(lavaan)
library(semTools)
library(haven)
library(ggcorrplot)
library(semPlot)
library(foreign)
library(MASS)
library(tidyr)
library(jtools)
library(dplyr)
library(cluster)
library(fpc)
library(ggplot2)
library(dendextend)
library(purrr)
library(ggpubr) # to use ggplotbar
2.读入数据
代码如下(示例):
setwd("F:/课题/数据/处理好的数据/20/")
raw_dt = read.xlsx2("*****.xlsx", sheetIndex = 1)
画图代码
箱线图
ggplot(dt1,aes(x=name,y=speed,fill=factor(name))) +
stat_boxplot(geom = 'errorbar')+
geom_boxplot() +
stat_compare_means(label.y=5,method = 'anova') +
labs(title = "你的标题")+
xlab("字符串")
##代码2
boxplot(speed~group_name, dt1, ylab = "speed, m/s",xlab= "A=60,B=40,C=20,单位:min",col = "bisque" )
增加显著性标志,加星星
ggplot(dt2,aes(x=Usedtime,y=Trust,fill=factor(Usedtime))) +
geom_boxplot() +
stat_boxplot(geom = 'errorbar')+
stat_compare_means(label.y=5.8,method = 'anova')+
stat_compare_means(comparisons = list(c(1,2),c(1,3),c(1,4),c(2,3),c(2,4),c(3,4)),label.y=c(4.9,5.2,5.5,5.7,5.9,6),label ='p.signif')+
#list(c(1,2),c(1,3)),label.y=c(4.9,5.2,5.5,5.7,5.9,6),label ='p.signif',hide.ns=T)+
labs(title = "特斯拉车主")+
xlab("使用时间")
双因素方差分析
双因素方差分析指的是,我们对于想要研究的某个变量,有两个变量会影响。 我这里研究的是驾驶模式(手动/自动)和驾驶时间(长/中/短)对于驾驶绩效的影响。 双因素分析代码
dt1 = read.csv("C:/Users/Heart/Desktop/接管绩效汇总_接管成功_control.csv")
attach(dt1)
aggregate(acc_x,by=list(group_name,control),FUN=mean,na.rm=TRUE)
aggregate(acc_x,by=list(group_name,control),FUN=sd,na.rm=TRUE)
fit_acc_x <- aov(acc_x~group_name*control)
summary(fit_acc_x)
总结
提示:这里对文章进行总结:
发布者:全栈程序员栈长,转载请注明出处:https://javaforall.cn/128465.html原文链接:https://javaforall.cn
边栏推荐
- BigDecimal 简介,常用方法
- IDEA connects to MySQL database and uses data
- In the future, the interviewer asks you why it is not recommended to use Select *, please answer him out loud!
- Redis与分布式:哨兵模式
- 3.爬虫之Scrapy框架1安装与使用
- "Listen to me, thank you" can be said in ancient poetry?Tsinghua University has developed an artifact of "Searching Sentences According to Meaning", which can search for the famous sayings you want wi
- 架构实战营模块8消息队列表结构设计
- The Selenium IDE of the Selenium test automation
- Asynchronous processing business using CompletableFuture
- 小试牛刀:Go 反射帮我把 Excel 转成 Struct
猜你喜欢
MySQL 23道经典面试吊打面试官
49.【拷贝构造函数与重载】
什么是消息队列呢?
Node version switching management using NVM
An article makes it clear!What is the difference and connection between database and data warehouse?
五个维度着手MySQL的优化
Spark学习(2)-Spark环境搭建-Local
Selenium自动化测试之Selenium IDE
Why do we need to sub-library and sub-table?
尚硅谷-JVM-内存和垃圾回收篇(P1~P203)
随机推荐
The pre-sale of the new Hyundai Paristi is open, and safety and comfort are not lost
C# using ComboBox control
In the future, the interviewer asks you why it is not recommended to use Select *, please answer him out loud!
搭建私有的的Nuget包服务器教程
C# Get network card information NetworkInterface IPInterfaceProperties
"Listen to me, thank you" can be said in ancient poetry?Tsinghua University has developed an artifact of "Searching Sentences According to Meaning", which can search for the famous sayings you want wi
Resnet&API
推荐系统-召回阶段-2013:DSSM(双塔模型)【Embedding(语义向量)召回】【微软】
The recently popular domestic interface artifact Apipost experience
OpenShift 4 - 定制 RHACS 安全策略,阻断生产集群使用高风险 Registry
Resolved (pymysqL connect to the database error) pymysqL. Err. ProgrammingError: (1146, "Table" test. Students' doesn 't exist ")
[QNX Hypervisor 2.2 User Manual] 9.13 rom
redhat/openssl generates a self-signed ca certificate and uses it
Shell脚本经典案例:探测批量主机是否存活
LeetCode只出现一次的数字
以后面试官问你 为啥不建议使用Select *,请你大声回答他!
2021 OWASP TOP 10 漏洞指南
MySQL 23道经典面试吊打面试官
LeetCode rotate array
Numbers that appear only once in LeetCode