R ggplot2:箱线图后面的打印线
我想用geom_line在我的箱线图后面绘制一条线,我最终设法将线图与箱线图结合起来。我有一个用于创建箱线图的数据集:R ggplot2:箱线图后面的打印线,r,plot,ggplot2,R,Plot,Ggplot2,我想用geom_line在我的箱线图后面绘制一条线,我最终设法将线图与箱线图结合起来。我有一个用于创建箱线图的数据集: >head(MdataNa) 1 2 3 4 5 6 7 1 -0.02798634 -0.05740014 -0.02643664 0.02203644 0.02366325 -0.02868668 -0.01278713
>head(MdataNa)
1 2 3 4 5 6 7
1 -0.02798634 -0.05740014 -0.02643664 0.02203644 0.02366325 -0.02868668 -0.01278713
2 0.20278229 0.19960302 0.10896017 0.24215229 0.31925211 0.29928739 0.15911725
3 0.06570653 0.08658396 -0.06019098 0.01437147 0.02078022 0.13814853 0.11369999
4 -0.42805441 -0.91945721 -1.05555731 -0.90877542 -0.77493682 -0.90620917 -1.00535742
5 0.39922939 0.12347996 0.06712451 0.07419287 -0.09517628 -0.12056720 -0.40863078
6 0.52821596 0.30827515 0.29733794 0.30555717 0.31636676 0.11592717 0.16957927
# glucose curve values
require("scales")
offconc <- c(0,0.4,0.8,1.8,3.5,6.9,7.3)
offtime <- c(9,11.4,12.9,14.9,16.7,18.3,20.5)
# now we have to scale them so they fit in the (boxplot)plot
time <- rescale(offtime, to=c(1,7))
conc <- rescale(offconc, to=c(-1,1))
glucoseConc <- data.frame(time,conc)
glucoseConc2 <- melt(glucoseConc, id = "time")
我有葡萄糖浓度,应该在这个方框图后面画一行:>head(MdataNa)
1 2 3 4 5 6 7
1 -0.02798634 -0.05740014 -0.02643664 0.02203644 0.02366325 -0.02868668 -0.01278713
2 0.20278229 0.19960302 0.10896017 0.24215229 0.31925211 0.29928739 0.15911725
3 0.06570653 0.08658396 -0.06019098 0.01437147 0.02078022 0.13814853 0.11369999
4 -0.42805441 -0.91945721 -1.05555731 -0.90877542 -0.77493682 -0.90620917 -1.00535742
5 0.39922939 0.12347996 0.06712451 0.07419287 -0.09517628 -0.12056720 -0.40863078
6 0.52821596 0.30827515 0.29733794 0.30555717 0.31636676 0.11592717 0.16957927
# glucose curve values
require("scales")
offconc <- c(0,0.4,0.8,1.8,3.5,6.9,7.3)
offtime <- c(9,11.4,12.9,14.9,16.7,18.3,20.5)
# now we have to scale them so they fit in the (boxplot)plot
time <- rescale(offtime, to=c(1,7))
conc <- rescale(offconc, to=c(-1,1))
glucoseConc <- data.frame(time,conc)
glucoseConc2 <- melt(glucoseConc, id = "time")
葡萄糖曲线值
要求(“天平”)
offconc这里有一个解决方案。
其思想是将x轴转换为连续值:
ggplot() +
geom_line(data=glucoseConc2,aes(x=time,y=value),group=1)+
geom_boxplot(data=stack(MdataNA), aes(x = as.numeric(ind), y = values, group=ind)) +
coord_cartesian(y = c(-1.5,1.5)) +
labs(list(title = "After Loess", x = "Timepoint", y = "M"))+
scale_x_continuous(breaks=1:7)
重新排列,以便在
geom\u行之后调用geom\u箱线图
。
这意味着您向geom\u行
提供了错误类型的数据。也许可以尝试清空ggplot
调用,因为所有内容都在geom中指定。这个概念确实有效:library(tidyverse);mtcars%%>%rownames_to_column('car')%%>%gather(var,val,-car)%%>%group_by(var)%%>%mutate(mean_val=mean(val))%%>%ggplot(aes(var,val))+geom_line(aes(var,mean_val),group=1)+geom_boxplot()
重复:可能重复@stibu我认为这不是重复。另一个Q是关于底图,而不是ggplot2
。这里的ggplot2
答案涉及添加一个简单的geom_hline
,它没有解决这里的问题。也许,还有另外一个DUP,但这不是一个好的。@ USS738。