R语言ggplot2绘图R语言做生信

跟着Y叔学ggstatplot

2018-08-04  本文已影响32人  热衷组培的二货潜

ggstatsplot

library(ggstatsplot)
library(gapminder)
ggstatsplot::ggbetweenstats(
  data = dplyr::filter(.data = gapminder, year == 2007),
  x = continent,
  y = lifeExp,
  messages = FALSE)
image.png
library(ggpubr)
set.seed(1234)
df <- data.frame( sex=factor(rep(c("f", "M"), each=200)), 
                  weight=c(rnorm(200, 55), rnorm(200, 58)))
ggdensity(df, x="weight", add = "mean", rug = TRUE, color = "sex", fill = "sex",
          palette = c("#00AFBB", "#E7B800"))
image.png
require(ggplot2)
p <- ggplot(df, aes(weight, fill=sex, color=sex)) + 
    geom_density(alpha=.5) + 
    geom_rug()
print(p)
image.png
require(dplyr)
df2 = group_by(df, sex) %>% summarize(m = mean(weight))
p + geom_vline(aes(xintercept=m, color=sex), df2, linetype='dashed') + 
    scale_fill_manual(values=c("#00AFBB", "#E7B800")) + 
    scale_color_manual(values=c("#00AFBB", "#E7B800"))
image.png
library(ggstatsplot)
ggpiestats(data = mtcars,
           main = am,                
           condition = cyl) +
  scale_fill_brewer(palette = "Dark2")
image.png
ggbetweenstats(data = iris, 
               x = Species, 
               y = Sepal.Length)
[图片上传中...(image.png-64750e-1533376305494-0)]
image.png
ggscatterstats(data = iris, 
               x = Sepal.Length, 
               y = Petal.Length,
               title = "Dataset: Iris flower data set")
image.png
ggscatterstats(data = iris, 
                x = Sepal.Length, 
                y = Petal.Length,
                title = "Dataset: Iris flower data set",marginal.type = "density")
image.png
ggscatterstats(data = iris, 
                x = Sepal.Length, 
                y = Petal.Length,
                title = "Dataset: Iris flower data set",marginal.type = "boxplot")
image.png
ggcorrmat(
   data = subset(iris, Species == "versicolor"),
   cor.vars = c(Sepal.Length, Sepal.Width, Petal.Length, Petal.Width))

参考链接:https://guangchuangyu.github.io/cn/2018/03/ggstatsplot/

上一篇 下一篇

猜你喜欢

热点阅读