Boxplot

作者: 余绕 | 来源:发表于2021-07-02 19:42 被阅读0次

1.最简单boxplot

library(reshape2)
library(ggplot2)
library(ggridges)
xqt <- read.csv("714.csv",header = T) #导入数据

data1=melt(xqt) #宽数据变成长数据
head(data1) 
tail(data1)

ggplot(data1,aes(x=data1$variable,y=data1$value))+
  geom_boxplot(aes(fill=data1$variable))+theme_bw()

2.自定义颜色的boxplots

library(reshape2)
library(ggplot2)
library(ggridges)
#boxplot
ggdata<- read.csv('714.csv')
head(ggdata)
ggdata1 <- melt(ggdata)
ggplot(ggdata1,aes(x=ggdata1$variable,y=ggdata1$value))+
  geom_boxplot(aes(fill=ggdata1$variable))+theme_bw()+
  scale_fill_manual(
    values = c("Aquamarine","Aquamarine","Gold","Gold","Magenta2","Magenta2")
    
  )

#另外一种赋值方式
values = c(
  "HY_CK_1"="Aquamarine",
  "HY_CK_2"="Aquamarine",
  "HY_KI_1"="Gold",
  "HY_KI_2"="Gold",
  "WM_CK_1"="Magenta2",
  "WM_CK_2"="Magenta2")

相关文章

网友评论

      本文标题:Boxplot

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