數(shù)據(jù)下載來源于:
https://raw.githubusercontent.com/holtzy/data_to_viz/master/Example_dataset/10_OneNumSevCatSubgroupsSevObs.csv
數(shù)據(jù)下載至本地使用
代碼參考: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=",")#加載數(shù)據(jù)
view(y)
colnames(y)
ggscatterstats(
data = y,#讀取數(shù)據(jù)
x = tip,
y = total_bill,
xlab = "tip",
ylab = "income",
title = "the relationship betwwen tip and income"#自己隨便命的名字
)
base_scatter.png
組合在一起的
?dplyr::filter
library(dplyr)#篩選數(shù)據(jù)的函數(shù)
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")
)
grouped_scatterplot.png