R中按组删除的图表

僧侣生活

我仍然是R的新手,想寻求有关绘制带状图的帮助。

stripchart(Study_intensive$AGE, method="stack",
at=c(0.05), pch=20, cex=2, xaxt="n", frame.plot=F, main= "Age Range in weight group(yr)")
axis(1, at=seq(0, 75, by=5) , labels= seq(0, 75, by=5),  
cex.axis=0.75)

这是我目前的代码,我正在尝试将其归类为另一个名为“ weightclass”的列;基本上为每个权重类使用另一种颜色。“ weightclass”具有4个值:分别为1、2、3、4。有什么我可以做的轻松做到的吗?

感谢您的帮助!

描述

这是一个使用示例mtcars

library(RColorBrewer)
testColor=brewer.pal(6, 'RdBu')
stripchart(mtcars$mpg~mtcars$gear, col=testColor, method="stack", pch=20, cex=2, xaxt="n", frame.plot=F, main= "Age Range in weight group(yr)")
axis(1, at=seq(0, 75, by=5) , labels= seq(0, 75, by=5), cex.axis=0.75)

编辑1

有了ggplot一种方法,可以将您要的全部信息汇总成一个条,并按组进行着色:

library(ggplot2)
library(RColorBrewer)
testColor=brewer.pal(6, 'RdBu')
mtcars$color=testColor[mtcars$gear] #to get the colors your after
mtcars$strip=1 #to get them into a single strip
ggplot(mtcars, aes(x=strip, y=mpg, color=color)) +
  geom_jitter(position=position_jitter(0.2)) + xlim(0, 2)

本文收集自互联网,转载请注明来源。

如有侵权,请联系 [email protected] 删除。

编辑于
0

我来说两句

0 条评论
登录 后参与评论

相关文章