美文网首页
R语言基础学习系列六-用ggplot2 画散点图

R语言基础学习系列六-用ggplot2 画散点图

作者: 小qqq | 来源:发表于2022-12-02 10:12 被阅读0次

数据下载来源于:
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"#自己随便命的名字
)
base_scatter.png

组合在一起的

?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")
)
grouped_scatterplot.png

相关文章

网友评论

      本文标题:R语言基础学习系列六-用ggplot2 画散点图

      本文链接:https://www.haomeiwen.com/subject/fyzefdtx.html