如何改变点并添加回归(用R)一cloudplot? [英] How to change points and add a regression to a cloudplot (using R)?

查看:282
本文介绍了如何改变点并添加回归(用R)一cloudplot?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

要弄清楚什么我问我创建了一个简单的例子。第一步是创建一些数据:

To make clear what I'm asking I've created an easy example. Step one is to create some data:

gender <- factor(rep(c(1, 2), c(43, 41)), levels = c(1, 2),labels = c("male", "female"))
numberofdrugs <- rpois(84, 50) + 1
geneticvalue <- rpois(84,75)
death <- rpois(42,50) + 15
y <- data.frame(death, numberofdrugs, geneticvalue, gender)

因此​​,这些都是一些随机的日期合并为一个 data.frame 。因此,从这些日期,我想绘制的云,我可以的男性和女性,并在那里我加了两个简单的回归(一个为女性和一个用于男性)之间的差异。所以,我已经开始了,但我不能得到的地方,我想这一点。请看下面是我到目前为止,完成的:

So these are some random dates merged to one data.frame. So from these dates I'd like to plot a cloud where I can differ between the males and females and where I add two simple regressions (one for females and one for males). So I've started, but I couldn't get to the point where I want to be. Please see below what I've done so far:

require(lattice)
cloud(y$death~y$numberofdrugs*geneticvalue)

xmale <- subset(y, gender=="male")
xfemale <- subset(y, gender=="female")

death.lm.male <- lm(death~numberofdrugs+geneticvalue, data=xmale)
death.lm.female <- lm(death~numberofdrugs+geneticvalue, data=xfemale)

我怎样才能使不同的点进行男性或女性使用云命令(例如蓝色和粉红色的点,而不是仅仅蓝十字)的时候,我怎么能添加两个估计模型到云图?

How can I make different points for males or females when using the cloud command (for example blue and pink points instead of just blue crosses) and how can I add the two estimated models to the cloud graph?

任何想到的是AP preciated!感谢您的想法!

Any thought is appreciated! Thanks for your ideas!

推荐答案

回答第一个你的问题的一半,我怎样才能让不同的点进行男性或女性使用云命令(例如蓝色和粉红色点的时候insted的只是蓝十字)?

Answer to the first half of your question, "How can I make different points for males or females when using the cloud command (for example blue and pink points insted of just blue crosses)?"

 cloud( death ~ numberofdrugs*geneticvalue , groups=gender, data=y )

荟萃答案,这可能会涉及一些非三维可视化。也许你可以用格子或GGPLOT2将数据分割成小的倍数?它可能会更玉米prehensible和可能更容易添加回归结果

The meta-answer to this may involve some non-3d visualization. Perhaps you can use lattice or ggplot2 to split the data into small multiples? It will likely be more comprehensible and likely easier to add the regression results.

splom( ~ data.frame( death, numberofdrugs, geneticvalue ), groups=gender, data=y )

默认splom面板功能是panel.pairs,你可以有可能修改它添加回归线没有麻烦了巨大的金额。

The default splom panel function is panel.pairs, and you could likely modify it to add a regression line without an enormous amount of trouble.

GGPLOT2做回归剧情基质中很容易,但我不能得到的颜色来工作。

ggplot2 does regressions within the plot matrix easily, but I can't get the colors to work.

pm <- plotmatrix( y[ , 1:3], mapping = aes(color=death) )
pm + geom_smooth(method="lm")

最后,如果你真的想要做一个cloudplot与回归平面,这里有一个方法使用scatterplot3d包做。请注意,我改变了数据有更有趣的结构看:

And finally, if you really want to do a cloudplot with a regression plane, here's a way to do it using the scatterplot3d package. Note I changed the data to have a little more interesting structure to see:

numberofdrugs <- rpois( 84, 50 ) + 1
geneticvalue <- numberofdrugs + rpois( 84, 75 )
death <- geneticvalue + rpois( 42, 50 ) + 15
y <- data.frame( death, numberofdrugs, geneticvalue, gender )

library(scatterplot3d) 
pts <- as.numeric( as.factor(y$gender) ) + 4
s <-scatterplot3d( y$death, y$numberofdrugs, y$geneticvalue, pch=pts, type="p", highlight.3d=TRUE )
fit <- lm( y$death ~ y$numberofdrugs + y$geneticvalue )
s$plane3d(fit)

这篇关于如何改变点并添加回归(用R)一cloudplot?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆