数据下载来源于:
https://raw.githubusercontent.com/holtzy/data_to_viz/master/Example_dataset/10_OneNumSevCatSubgroupsSevObs.csv
数据下载至本地使用
代码参考:ggplot2 Based Plots with Statistical Details • ggstatsplot (indrajeetpatil.github.io)
用到两个包一个ggststsplot,一个是ggside
大家一起学习,共同进步,有一起学习R的小伙伴可以加和好友互相学习
library(ggstatsplot)
install.packages("ggside")
library(ggside)
getwd()
y <- read.table("D:/biolearning/Rcourse/happy.txt", header=T, sep=",")#加载数据
view(y)
colnames(y)
ggscatterstats(
data = y,#读取数据
x = tip,
y = total_bill,
xlab = "tip",
ylab = "income",
title = "the relationship betwwen tip and income"#自己随便命的名字
)
组合在一起的
?dplyr::filter
library(dplyr)#筛选数据的函数
head(y)
grouped_ggscatterstats(
data = dplyr::filter(y, sex %in% c("Female", "Male")),
x = tip,
y = total_bill,
grouping.var = sex,
xlab = "tip",
ggtheme = ggplot2::theme_grey(),
ggplot.component = list(ggplot2::scale_x_continuous(breaks = seq(2, 9, 1), limits = (c(2, 9)))),
plotgrid.args = list(nrow = 1),
annotation.args = list(title = "the relationship betwwen tip and income")
)